题目链接:http://poj.org/problem?id=2684
属于比较水的计算几何题目,直接叉积判断即可。
1 //STATUS:C++_AC_0MS_192KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include<algorithm> 9 #include<vector> 10 #include<queue> 11 #include<stack> 12 using namespace std; 13 #define LL __int64 14 #define pii pair<int,int> 15 #define Max(a,b) ((a)>(b)?(a):(b)) 16 #define Min(a,b) ((a)<(b)?(a):(b)) 17 #define mem(a,b) memset(a,b,sizeof(a)) 18 #define lson l,mid,rt<<1 19 #define rson mid+1,r,rt<<1|1 20 const int N=55,INF=0x3f3f3f3f,MOD=100000000; 21 const double DNF=100000000000; 22 23 struct Node{ 24 double x,y; 25 }nod[N][12]; 26 27 int n,cou[N]; 28 29 double dist(Node &a) 30 { 31 return a.x*a.x+a.y*a.y; 32 } 33 34 void getr(Node& r,Node& a,Node& b) 35 { 36 r.x=a.x-b.x; 37 r.y=a.y-b.y; 38 } 39 40 double cha(Node& r1,Node& r2) 41 { 42 return r1.x*r2.y-r2.x*r1.y; 43 } 44 45 int judge(int k,int sta,int dir) 46 { 47 int i,j; 48 Node r0,rj,r01,rj1; 49 for(i=1,j=sta+dir;i<cou[0];i++,j+=dir){ 50 getr(r0,nod[0][i],nod[0][i-1]); 51 getr(rj,nod[k][j],nod[k][j-dir]); 52 if(dist(r0)!=dist(rj))return 0; 53 if(i<cou[0]-1){ 54 getr(r01,nod[0][i+1],nod[0][i]); 55 getr(rj1,nod[k][j+dir],nod[k][j]); 56 if(cha(r01,r0)!=cha(rj1,rj))return 0; 57 } 58 } 59 return 1; 60 } 61 62 int main() 63 { 64 // freopen("in.txt","r",stdin); 65 int i,j; 66 while(~scanf("%d",&n) && n) 67 { 68 for(i=0;i<=n;i++){ 69 scanf("%d",&cou[i]); 70 for(j=0;j<cou[i];j++) 71 scanf("%lf%lf",&nod[i][j].x,&nod[i][j].y); 72 } 73 74 for(i=1;i<=n;i++){ 75 if(cou[i]!=cou[0])continue; 76 if(judge(i,0,1) || judge(i,cou[i]-1,-1)) 77 printf("%d\n",i); 78 } 79 printf("+++++\n"); 80 } 81 return 0; 82 }