USACO rectbarn

第六章干掉第二题了— —+

虽然是看过答案之后才干掉的……

详细参见03年王知昆论文,

那个O(mn)的算法能过

由于点太多了,O(S^2)的会超时

 

/* ID: biran001 PROG: rectbarn LANG: C++ */ #include<stdio.h> #include<string.h> #define FOR(i,s,e) for(int i=s;i<e;i++) #define FORR(i,s,e) for(int i=s;i>e;i--) int c,r,p; int hight[3002],left[3002],right[3002],leftX[3002],rightX[3002]; bool g[3002][3002]; inline int max(int a,int b) {return a>b?a:b;} inline int min(int a,int b) {return a<b?a:b;} int ans; int main() { freopen("rectbarn.in","r",stdin); freopen("rectbarn.out","w",stdout); // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); memset(g,false,sizeof(g)); scanf("%d%d%d",&r,&c,&p); int a,b; FOR(i,0,c+2)g[0][i]=true; FOR(i,0,r+2)g[i][0]=g[i][c+1]=true; FOR(i,0,p) { scanf("%d%d",&a,&b); g[a][b]=true; } FOR(i,1,c+1){left[i]=0;right[i]=c+1;} leftX[0]=0; rightX[c+1]=c+1; FOR(i,1,c+1)hight[i]=0; ans=-1; FOR(C,1,r+1) { FOR(i,1,c+1) leftX[i]=g[C][i-1]? i-1:leftX[i-1]; FORR(i,c,0) rightX[i]=g[C][i+1]? i+1:rightX[i+1]; FOR(i,1,c+1) { if(g[C][i]) { hight[i]=0; left[i]=0; right[i]=c+1; } else { hight[i]=hight[i]+1; left[i]=max(leftX[i],left[i]); right[i]=min(rightX[i],right[i]); } ans=max(ans,hight[i]*(right[i]-left[i]-1)); // printf("%d %d %d ",hight[i],left[i],right[i]); }//putchar(10); } printf("%d/n",ans); }  

你可能感兴趣的:(c,算法)