[NOIP2019 simulation game] LuoguP4261 platinum heads of state and Claudia Fernandez

Title Description

N is given rectangular coordinates, a rectangular type per unit time of a mobile unit in the positive x-axis direction, a rectangular type 2 in the y-axis positive direction, the original rectangle do not overlap, a point is rectangular footprint iff it is within the rectangle (free boundary), seeking $ (- \ infty, + \ infty) $ time point a maximum number of rectangles to be covered. n <= 10 ^ 5.

analysis

The part can be really give, $ n ^ 2 $ can get 80pts (however I n == 2 special judge wrong (do not know why I puts ( "0") the qwq) becomes 70pts)

First: We can as a rectangular moving vertically stationary, the sideways movement as a rectangular extension of k = the slope of the linear movement of the rectangular -1

  For a start there is no repeat rectangle, so in the end only a maximum of two repeats, so the answer is not 1, that is, 2

  So we output rand ()% 2 + 1

  This question as to when the examination of computational geometry do ...

Consider $ n ^ 2 $ practices:

  It can be obtained from the above analysis, if the answer is 2, only three cases:

  0 are enumerated a rectangle and each rectangle is determined there is an overlap enough

  Note that when the check can take an equal sign

Consider optimization:

  Obviously we can convert this problem into sections covering each rectangle becomes this line:

$$(x_2-x_1-w_1,x_2+w_2-x_1)$$

with

$$(y_1-y_2-h_2,y_1+h_1-y_2)$$

Then simplify it, do just fine with a greedy interval coverage (more than I hit the $ n ^ 2 $ is also simple ...)

 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 inline int read(){
 4     int ans=0,f=1;char chr=getchar();
 5     while(!isdigit(chr)){if(chr=='-')f=-1;chr=getchar();}
 6     while(isdigit(chr)) {ans=(ans<<3)+(ans<<1)+chr-48;chr=getchar();}
 7     return ans*f;
 8 }const int M = 1e5+5;
 9 int n,T,n1,n2;
10 //-----------------------------------n^2暴力做法------------------------------------ 
11 struct P{int x,y,w,h;}a[M],b[M];
12 struct Poi{int x,y;};
13 struct Line{int a[2];}ll[M];
14 int L[M];
15 int s[1001][1001];
16 inline bool check_up(Poi x,int l){
17     int y=-x.x+l;
18     if(x.y>y) return 1;
19     return 0;
20 }
21 inline bool check_down(Poi x,int l){
22     int y=-x.x+l;
23     if(x.y<y) return 1;
24     return 0;
25 }
26 inline bool check(Poi x,Poi y,int l1,int l2){
27     int y1=-x.x+l1,y2=-y.x+l2;
28     if(x.y>=y1&&y.y<=y2) return 1;
29     return 0;
30 }
31 inline void Solve_1(){
32     n=read();n1=0,n2=0;
33     for(int i=1;i<=n;i++){
34         int x=read(),y=read(),w=read(),h=read(),d=read();
35         if(d==0)
36             a[++n1]=(P){x,y,w,h};
37         else b[++n2]=(P){x,y,w,h};
38     }
39     for(int i=1;i<=n1;i++){
40         ll[i].a[0]=a[i].x+a[i].y;
41         ll[i].a[1]=a[i].x+a[i].y+a[i].w+a[i].h;
42     }int ff=0;
43     for(int i=1;i<=n2;i++){
44         Poi A,B;
45         A=(Poi){b[i].x,b[i].y};
46         B=(Poi){b[i].x+b[i].w,b[i].y+b[i].h};                
47         for(int j=1;j<=n1;j++){
48             if(check_down(A,ll[j].a[0])&&check_up(B,ll[j].a[0])||
49                check_down(A,ll[j].a[1])&&check_up(B,ll[j].a[1])||
50                check(A,B,ll[j].a[0],ll[j].a[1]))
51                 {ff=1;break;}
52         }
53     }if(!ff) puts("1");else puts("2");
54 }
55 //-------------------------------------------------------------------------------------------- 
56 int lst[M],ff;
57 struct PP{int x,y,type;}seg[M];
58 bool cmp(const PP&a,const PP&b){return a.x==b.x&&a.y<b.y||a.x<b.x;}
59 inline void Solve(){
60     n=read(),ff=0;
61     for(int i=1;i<=n;i++){
62         int x=read(),y=read(),w=read(),h=read(),d=read();
63         seg[i]=(PP){x+y,x+y+w+h,d};
64     }sort(seg+1,seg+n+1,cmp);
65     memset(lst,-0x3f,sizeof(lst));
66     for(int i=1;i<=n;i++){
67         if(seg[i].x<lst[seg[i].type^1]){
68             puts("2");
69             ff=1;break;
70         }lst[seg[i].type]=max(lst[seg[i].type],seg[i].y);
71     }if(!ff)puts("1");
72 }
73 int main(){
74     freopen("cloud.in","r",stdin);
75     freopen("cloud.out","w",stdout);
76     T=read();
77     while(T--){
78 //        Solve_1();
79         Solve();
80     }
81     return 0;
82 }

 

Guess you like

Origin www.cnblogs.com/zhenglw/p/11348401.html