【Luogu】P1578奶牛浴场(DP,枚举)
枚举极大子矩形。详情请见本题题解:I_AM_HelloWord
代码如下
#include<cstdio> #include<cctype> #include<algorithm> inline long long read(){ long long num=0,f=1; char ch=getchar(); while(!isdigit(ch)){ if(ch=='-') f=-1; ch=getchar(); } while(isdigit(ch)){ num=num*10+ch-'0'; ch=getchar(); } return num*f; } struct Que{ int y,x; bool operator <(const Que a)const{ return y<a.y; } }point[100000]; int ans; int main(){ int L=read(),W=read(),n=read(); point[1]=(Que){0,0}; point[2]=(Que){0,L}; point[3]=(Que){W,0}; point[4]=(Que){W,L}; for(int i=1;i<=n;++i) point[i+4]=(Que){read(),read()}; n+=4; std::sort(point+1,point+n+1); for(int i=1;i<=n;++i){ int l=point[i].y,r=L,u=0,d=W; for(int j=i+1;j<=n;++j){ r=point[j].y; ans=std::max(ans,(r-l)*(d-u)); if(point[j].x==point[i].x) break; else if(point[j].x>point[i].x) d=std::min(d,point[j].x); else u=std::max(u,point[j].x); r=L; } } printf("%d",ans); return 0; }