E. The Supersonic Rocket Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)

http://codeforces.com/contest/1017/problem/E

 

凸包模板+kmp

  1 #include <cstdio>
  2 #include <cstdlib>
  3 #include <cmath>
  4 #include <cstring>
  5 #include <time.h>
  6 #include <string>
  7 #include <set>
  8 #include <map>
  9 #include <list>
 10 #include <stack>
 11 #include <queue>
 12 #include <vector>
 13 #include <bitset>
 14 #include <ext/rope>
 15 #include <algorithm>
 16 #include <iostream>
 17 using namespace std;
 18 #define ll long long
 19 #define minv 1e-10
 20 #define inf 1e9
 21 #define pi 3.1415926536
 22 #define E  2.7182818284
 23 const ll mod=1e9+7;//998244353
 24 const int maxn=1e5+10;
 25 
 26 struct node
 27 {
 28     ll x,y;
 29 }a[maxn],b[maxn],e[maxn],f[maxn],point;
 30 
 31 int p[maxn*6];
 32 double c[maxn*6],d[maxn*6];
 33 
 34 ///result only 1/0
 35 int cmp(node a,node b)
 36 {
 37     ll s=(a.y-point.y)*(b.x-point.x) - (b.y-point.y)*(a.x-point.x);
 38     if (s<0)
 39         return 1;
 40     else if (s>0)
 41         return 0;
 42     else
 43         return pow(a.y-point.y,2)+pow(a.x-point.x,2) < pow(b.y-point.y,2)+pow(b.x-point.x,2);
 44 }
 45 
 46 void work(node a[],double c[],node e[],int n,int* z)
 47 {
 48     int i,g;
 49     for (i=1;i<=n;i++)
 50     {
 51         scanf("%lld%lld",&a[i].x,&a[i].y);
 52         if (a[1].x>a[i].x || (a[1].x==a[i].x && a[1].y>a[i].y))
 53             swap(a[i],a[1]);
 54     }
 55     point=a[1];
 56     sort(a+2,a+n+1,cmp);
 57 
 58     e[1].x=a[1].x,e[1].y=a[1].y;
 59     e[2].x=a[2].x,e[2].y=a[2].y;
 60     g=2;
 61     for (i=3;i<=n;i++)
 62     {
 63         while (g>1 && (a[i].x-e[g-1].x)*(e[g].y-e[g-1].y)-(e[g].x-e[g-1].x)*(a[i].y-e[g-1].y)>=0)
 64             g--;
 65         g++;
 66         e[g].x=a[i].x,e[g].y=a[i].y;
 67     }
 68     e[g+1]=e[1];
 69     e[0]=e[g];
 70 
 71     for (i=1;i<=g;i++)
 72     {
 73         //len^2 cos(angle)
 74         c[i*2-1]=(double)(pow(e[i+1].x-e[i].x,2) + pow(e[i+1].y-e[i].y,2));
 75 
 76         ll b1=pow(e[i+1].y-e[i].y,2)+pow(e[i+1].x-e[i].x,2),
 77         b2=pow(e[i-1].y-e[i].y,2)+pow(e[i-1].x-e[i].x,2),
 78         b3=pow(e[i+1].y-e[i-1].y,2)+pow(e[i+1].x-e[i-1].x,2);
 79 
 80         c[i*2]=1.0*(b1+b2-b3)/2/sqrt(b1)/sqrt(b2);
 81     }
 82     (*z)=g*2;
 83 }
 84 
 85 int main()
 86 {
 87     int n,m,g1,g2,i,j;
 88     scanf("%d%d",&n,&m);
 89     work(a,c,e,n,&g1);
 90     work(b,d,f,m,&g2);
 91     if (g1!=g2)
 92     {
 93         printf("NO");
 94         return 0;
 95     }
 96     for (i=1;i<=g2;i++)
 97         d[i+g2]=d[i];
 98     g2<<=1;
 99 
100     p[1]=0;
101     j=0;
102     for (i=2;i<=g1;i++)
103     {
104         while (j>0 && fabs(c[j+1]-c[i])>minv)
105             j=p[j];
106         if (fabs(c[j+1]-c[i])<minv)
107             j++;
108         p[i]=j;
109     }
110 
111     j=0;
112     for (i=1;i<=g2;i++)
113     {
114         while (j>0 && fabs(c[j+1]-d[i])>minv)
115             j=p[j];
116         if (fabs(c[j+1]-d[i])<minv)
117             j++;
118         if (j==g1)
119         {
120             printf("YES");
121             return 0;
122         }
123     }
124     printf("NO");
125     return 0;
126 }
127 /*
128 6 5
129 1 100000000
130 2 100000000
131 3 100000000
132 4 100000000
133 5 100000000
134 6 1
135 
136 2 100000000
137 6 1
138 3 100000000
139 1 100000000
140 5 100000000
141 */

 

posted @ 2018-08-30 12:11  congmingyige  阅读(203)  评论(0编辑  收藏  举报