USACO 6.1.2 rectbarn
2012-07-01 19:10
239 查看
题目:
http://ace.delos.com/usacoprob2?a=JsPN70PkuJW&S=rectbarn
http://pingce.ayyz.cn:9000/usaco/data/20110129214306/rectbarn.html
Ever the capitalist, Farmer John wants to extend his milking business by purchasing more cows. He needs space to build a new barn for the cows.
FJ purchased a rectangular field with R (1 ≤ R ≤ 3,000) rows numbered 1..R and C (1 ≤ C ≤ 3,000) columns numbered 1..C. Unfortunately, he realized too late that some 1x1 areas in the field are damaged, so he cannot build the barn on the entire RxC field.
FJ has counted P (0 ≤ P ≤ 30,000) damaged 1x1 pieces and has asked for your help to find the biggest rectangular barn (i.e., the largest area) that he can build on his land without building on the damaged pieces.
Lines 2..P+1: Each line contains two space-separated integers, r and c, that give the row and column numbers of a damaged area of the field
Pieces marked with 'X' are damaged and pieces marked with '#' are part of the new barn.
题解:
这题与03年王知昆的论文中所举的例子并无二异,论文当中给出了两种做法,一种是O(P^2)的,另一种是O(R*C)。本题由于数据范围的约束只能使用第二种悬线的NB的dp,详见论文。
View Code
http://ace.delos.com/usacoprob2?a=JsPN70PkuJW&S=rectbarn
http://pingce.ayyz.cn:9000/usaco/data/20110129214306/rectbarn.html
A Rectangular Barn
Mircea Pasoi -- 2003Ever the capitalist, Farmer John wants to extend his milking business by purchasing more cows. He needs space to build a new barn for the cows.
FJ purchased a rectangular field with R (1 ≤ R ≤ 3,000) rows numbered 1..R and C (1 ≤ C ≤ 3,000) columns numbered 1..C. Unfortunately, he realized too late that some 1x1 areas in the field are damaged, so he cannot build the barn on the entire RxC field.
FJ has counted P (0 ≤ P ≤ 30,000) damaged 1x1 pieces and has asked for your help to find the biggest rectangular barn (i.e., the largest area) that he can build on his land without building on the damaged pieces.
PROGRAM NAME: rectbarn
INPUT FORMAT
Line 1: Three space-separated integers: R, C, and P.Lines 2..P+1: Each line contains two space-separated integers, r and c, that give the row and column numbers of a damaged area of the field
SAMPLE INPUT (file rectbarn.in)
3 4 2 1 3 2 1
OUTPUT FORMAT
Line 1: The largest possible area of the new barnSAMPLE OUTPUT (file rectbarn.out)
6
OUTPUT DETAILS
1 2 3 4 +-+-+-+-+ 1| | |X| | +-+-+-+-+ 2|X|#|#|#| +-+-+-+-+ 3| |#|#|#| +-+-+-+-+
Pieces marked with 'X' are damaged and pieces marked with '#' are part of the new barn.
题解:
这题与03年王知昆的论文中所举的例子并无二异,论文当中给出了两种做法,一种是O(P^2)的,另一种是O(R*C)。本题由于数据范围的约束只能使用第二种悬线的NB的dp,详见论文。
View Code
/* ID:zhongha1 PROB:rectbarn LANG:C++ */ #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; const int maxn=3001; int n,m,p,ans,left[maxn],right[maxn],h[2][maxn],l[2][maxn],r[2][maxn]; bool use[maxn][maxn]; int main() { freopen("rectbarn.in","r",stdin); freopen("rectbarn.out","w",stdout); scanf("%d%d%d",&n,&m,&p); for (int a=1;a<=p;a++) { int x,y; scanf("%d%d",&x,&y); use[x][y]=true; } for (int a=1;a<=m;a++) l[0][a]=1,r[0][a]=m; for (int a=1;a<=n;a++) { int nowl=1; for (int b=1;b<=m;b++) if (use[a][b]) nowl=b+1; else left[b]=nowl; nowl=m; for (int b=m;b>=1;b--) if (use[a][b]) nowl=b-1; else right[b]=nowl; for (int b=1;b<=m;b++) if (use[a][b]) { h[a % 2][b]=0; l[a % 2][b]=0; r[a % 2][b]=m; } else { h[a % 2][b]=h[1-a % 2][b]+1; l[a % 2][b]=max(left[b],l[1-a % 2][b]); r[a % 2][b]=min(right[b],r[1-a % 2][b]); ans=max(h[a % 2][b]*(r[a % 2][b]-l[a % 2][b]+1),ans); } } printf("%d\n",ans); return 0; }
相关文章推荐
- USACO6.1.2 A Rectangular Barn(rectbarn)
- USACO 6.1.2 A Rectangular Barn
- usaco training 6.1.2 A Rectangular Barn 题解
- USACO rectbarn
- USACO 6.1.2 A Rectangular Barn 单调栈
- [USACO 6.1.2] A Rectangular Barn
- USACO Big Barn 解题报告
- [USACO12DEC]逃跑的BarnRunning Away From…
- USACO 1.3 - Barn Repair(贪心)
- [USACO]Barn Repair
- usaco 1.3 barn repair...有意思...
- [USACO 12DEC]Running Away From the Barn
- Barn Repair USACO
- [USACO 3.1.4]rect1(漂浮法/矩形切割)
- usaco6.1.2 A Rectangular Barn
- bzoj 1696: [Usaco2007 Feb]Building A New Barn新牛舍 ——中位数排序
- 【基础算法】【usaco 3.1.4】rect1
- usaco 24 barn repair
- USACO rect1 离散化
- usaco Barn Repair (牛宿舍问题||贪心)