CF Gym 100463D Evil prefix and + discrete

Source: Internet
Author: User
Tags define local

Test instructions: For some colored dots, find the smallest rectangle, which exactly includes half of the red dots, and does not include the blue dots.

Solving: Violence, seeking a two-dimensional prefix and, with the principle of tolerance to update. n is small so I used discrete optimization and ran a 0ms.

Did not write two-dimensional prefix and, plus discrete write is not very skilled, so engaged for 2 hours, fortunately is a one-off. There seems to be a hole, the line does not special, or WA.

#include <cstdio>#include<cmath>#include<vector>#include<map>#include<Set>#include<algorithm>#include<cstring>using namespacestd;//#define LOCALConst intMAXN = -;intRed;intx[maxn],szx;inty[maxn],szy;intG[MAXN][MAXN];intSUMB[MAXN][MAXN];intSUMA[MAXN][MAXN];structpoi{intx, y; intTP; intSx,sy; BOOL operator< (ConstPoi & RHS)Const {        returnX < Rhs.x | | (x = = Rhs.x && y <rhs.y); }    voidinput () {scanf ("%d%d%d",&x,&y,&TP); if(!TP) red++; }    voidGetdis () {SX= Lower_bound (x,x+szx,x)-X; Sy= Lower_bound (y,y+szy,y)-Y; G[sx][sy]=TP; }}P[MAXN];Const intINF =0x7fffffff;intMain () {#ifdef local freopen ("In.txt","R", stdin); //freopen ("OUT.txt", "w", stdout);#endif //Local    intN; intCAS =0;  while(~SCANF ("%d", &n) &&N) {Red=0; memset (G,-1,sizeof(G)); intMinx = INF, Miny =INF;  for(inti =0; i < N; i++) {p[i].input (); Minx=min (minx,p[i].x); Miny=min (miny,p[i].y); //Y[i] = p[i].y;} x[0] = minx-1; y[0] = miny-1 ;  for(inti =1; I <= N; i++) {X[i]= p[i-1].x; Y[i]= p[i-1].y; } sort (X,x+n+1); Sort (Y,y+n+1); Szy= Unique (y,y+n+1) -Y; SZX= Unique (x,x+n+1) -X; memset (Suma,0,sizeof(Suma)); memset (Sumb,0,sizeof(SUMB));  for(inti =0; i < N; i++) P[i].        Getdis ();  for(inti =1; i < SZX; i++)         for(intj =1; J < Szy; J + +) {Suma[i][j]= suma[i-1][j]+suma[i][j-1]-suma[i-1][j-1]+ (g[i][j]==1); SUMB[I][J]= sumb[i-1][j]+sumb[i][j-1]-sumb[i-1][j-1]+ (g[i][j]==0); } Red>>=1; intArea =INF;  for(intLX =0; LX < SZX; lx++){             for(intRx = lx+1; Rx < SZX; rx++){                 for(intly =0; Ly <szy; ly++){                     for(intry = ly+1; Ry < szy; ry++){                        if(Suma[rx][ry]-suma[rx][ly]-suma[lx][ry]+suma[lx][ly])Continue; if(Red = = sumb[rx][ry]-sumb[rx][ly]-sumb[lx][ry]+sumb[lx][ly]) { Area= Min (area, x[rx]-x[lx+1]) * (y[ry]-y[ly+1])); } }}}} printf ("Case %d:%d\n", ++cas,area!=inf?area:-1); }    return 0;}

CF Gym 100463D Evil prefix and + discrete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.