Advertising:
#include <stdio.h>int main(){ puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44095063");}
Test instructions
The coordinate system gives n points, which are "H" and "G", and at most one point on the hour coordinate.
Now ask for a sub-rectangle that contains as many "H" as possible without "G", and then the minimum area to keep "H" in the most cases.
The maximum number of output "H", and the minimum rectangular area at which "H" is guaranteed.
Exercises
We find that the coordinates are limited [0,1000] (note that there is a "0"!!!), so it is a rectangle.
First question:
First we can calculate all the maximal sub-rectangles by referring to the maximal sub-rectangles, and then maintain a F i,J Said [ Span class= "mn" id= "mathjax-span-13" style= "Font-family:mathjax_main;" >1 i [ 1 , j How many "H" points are in this rectangle, and the number of "h" can be calculated for a rectangular O (1) time.
Second question:
We can then cut out the extra corners of each large rectangle to calculate the area.
We can make two points, see how many in four directions can be cut, check is the number of "H" in the rectangle is 0.
Of course, about can actually divide the O (1) to calculate out, eh I now found all have added Logn, left and right to write what O (1) Ah, pop qwq.
Then do not say, want to know yourself to see the code it.
There is no need to cut below.
Do not write, do not write, do not understand the message bar.
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 1010#define INF 0x3f3f3f3fusing namespace STD;int MapN [N],f[n][n];structdata{intH,h;//maximum distance, nearest white point intL,r;//approx. effective distance}s[n];intAnsa,ansb=inf;intQ[n];inline intGetans (intAintBintCintD) {returnF[d][b]-f[d][a]-f[c][b]+f[c][a];}inline intGetarea (intAintBintCintD) {intL=c,r=d,mid,ans; while(L<=R) {if(r-l<=3) {ans=l; for(inti=r;i>=l;i--)if(Getans (a,b,c,i) = =0) {ans=i; Break;} Break; } mid=l+r>>1;if(Getans (a,b,c,mid) = =0) L=mid;Elser=mid-1; }return(b-a-1) * (d-ans-1);}intMain () {intI,j,k;intA,b,c;scanf("%d", &c);Charss[5]; while(c--) {scanf("%d%d%s", &A,&B,SS), a++,b++;if(ss[0]==' H ')MapA [b]=1;//Can Else MapA [b]=2;//No} for(i=1; i<=1001; i++) {inttemp=0; for(j=1; j<=1001; j + +) {if(MapI [j]==1) temp++; f[i][j]=f[i-1][j]+temp; } } for(i=1; i<=1001; i++) S[i].h=inf;intL,r; for(i=1; i<=1001; i++) { for(j=1; j<=1001; j + +) {if(MapI [j]==2) S[j]. H=0, S[j].h=inf;Else{S[j]. h++;if(MapI [j]==1) s[j].h=1;Elses[j].h++; } s[j].l=s[j].r=j; } l=1, r=0; for(j=1; j<=1001; j + +) { while(L<=r&&s[q[r]]. H>=S[J]. H) S[j].l=s[q[r--]].l; while(S[j].l<j&&s[s[j].l].h>s[j]. H) s[j].l++; Q[++r]=j; } l=1, r=0; for(j=1001; j;j--) { while(L<=r&&s[q[r]]. H>=S[J]. H) S[J].R=S[Q[R--]].R; while(S[j].r>j&&s[s[j].r].h>s[j]. H) s[j].r--; Q[++r]=j; } for(j=1; j<=1001; j + +) {intRet=getans (s[j].l-1, S[j].r,i-s[j]. H,i);if(Ret>=ansa) {intTemp=getarea (s[j].l-1, S[j].r,i-s[j]. H,i);if(Ret==ansa) ansb=min (ansb,temp);ElseAnsa=ret,ansb=temp; } } }printf("%d\n%d\n", ANSA,ANSB);return 0;}
"BZOJ3885" "Usaco2015 Jan" Cow rectangles a strange largest sub-rectangle