[Hdu contest 2019-07-29] Azshara's deep sea dynamic programming interval dp computational geometry convex hull scanning graham

Today the first question hdu of the game, the convex hull + interval dp.

Gives m round n points, n <400, m <100, the convex hull is then asked to identify the convex hull to the connection point, the connection point can not be two adjacent (on the convex package), the connection can not intersect or tangent to the circle, the connection can not intersect but there may be common endpoint.

First identify the convex hull, then n * n and m edges round off point to the straight line distance verify whether the edge intersects the circle to the stored e [n] [n] where.

Then obviously a dp, but I began to think that the wrong topic can not have a common endpoint, to have a common endpoint circumstances consider looking like a triangular process, that is, the interval dp.

Dp wonderful bit interval where the maximum interval range of the convex hull points instead of +1, since the two-dot chain line is not adjacent in the convex hull so this maximum value can be obtained directly.

Today crazy pit teammates, if I helped his teammates will be able to troubleshoot pairs a question, because the food did not write himself out of the question also hurt teammates really, really sorry.

In the following code, and the code can be considered a review dp find the convex hull of the board, this method is like asking graham scanning?

 1 #include<iostream>
 2 #include<cmath>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<string>
 7 #include<algorithm>
 8 #include<vector>
 9 #include<iomanip>
10 #include<stack>
11 #include<queue> 
12 using namespace std;
13 const int maxn=410;
14 int n,m,cnt;
15 int tot;
16 double r;
17 struct nod{
18     double x,y;
19 }poi[maxn],po[maxn*2],ci[maxn];
20 bool e[maxn][maxn]={};
21 int f[maxn*2][maxn*2]={};
22 bool cmp(nod a,nod b){
23     double aa=atan2(a.y-po[1].y,a.x-po[1].x);
24     double bb=atan2(b.y-po[1].y,b.x-po[1].x);
25     if(aa==bb) return a.x<b.x;
26     return aa<bb;
27 }
28 double cro(nod a,nod b,nod c){
29     return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
30 }
31 void getpo(){
32     int t=1;
33     for( int i=2; i<=n; ++i) {
34         if( poi[i].y < poi[t].y||( poi[i].y == poi[t].y&&poi[i].x < poi[t].x) ) t=i;
35     }
36     po[++cnt]=poi[t];swap(poi[t],poi[1]);
37     sort(poi+2,poi+n+1,cmp);
38     po[++cnt]=poi[2];
39     for(int i=3;i<=n;++i){
40         //cout<<poi[i].x<<poi[i].y<<endl;
41         while(cnt>1&&cro(po[cnt-1],poi[i],po[cnt])>=0)--cnt;
42         po[++cnt]=poi[i];
43     }
44 }
45 int main(){
46     int T;scanf("%d",&T);
47     while(T--){
48         tot=1;
49         cnt=0;
50         memset(e,0,sizeof(e));
51         memset(f,0,sizeof(f));
52         scanf("%d%d%lf",&n,&m,&r);
53         for( int i=1; i<=n; ++i) scanf("%lf%lf",&poi[i].x,&poi[i].y);
54         for( int i=1; i<=m; ++i) scanf("%lf%lf",&ci[i].x,&ci[i].y);
55         getpo();//cout<<1111111<<endl;
56         for(int i=1;i<=cnt;++i){
57         //    cout<<po[i].x<<po[i].y<<endl;
58             for(int j=i+2;j<=cnt;++j){
59                 if(i==1&&j==cnt)continue;
60                 double a=po[i].y-po[j].y,b=po[j].x-po[i].x;
61                 double c=-(a*po[i].x+b*po[i].y);
62                 e[i][j]=1;
63                 e[j][i]=1;
64                 for(int w=1;w<=m;++w){
65                     double ju=a*ci[w].x+b*ci[w].y+c;
66                     if(ju<0)ju=-ju;
67                     ju/=sqrt(a*a+b*b);
68                     if(ju>r)continue;
69                     e[i][j]=0;
70                     e[j][i]=0;
71                 }
72                     //cout<<i<<j<<e[i][j]<<endl;
73             }
74         }
75         int ans=0;
76         for(int k=1;k<=cnt;++k){
77             for(int i=1,j=k;j<cnt*2;++i,++j){
78                 for(int t=i;t<=j;++t){
79                     f[i][j]=max(f[i][j],f[i][t]);
80                     if(e[(t-1)%cnt+1][(j-1)%cnt+1])f[i][j]=max(f[i][j],f[i][t]+1);
81                 }
82             }
83         }
84         for(int i=1;i<=cnt;++i)ans=max(ans,f[i][i+cnt-1]);
85         printf("%d\n",ans);
86     }
87     return 0;
88 }
View Code

 

Guess you like

Origin www.cnblogs.com/137shoebills/p/11267278.html