hdu 4082 Hou Yi's secret(暴力枚举)
Hou Yi's secret
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1881 Accepted Submission(s): 450
Problem Description
Long long ago, in the time of Chinese emperor Yao, ten suns rose into the sky. They burned the crops and scorched the bushes and trees, leaving the people with nothing to eat. Hou Yi was the greatest archer at that time. Yao wanted him to shoot down nine suns. Hou Yi couldn't do that job with ordinary arrows. So Yao send him to God to get some super powerful magic arrows. Before Hou Yi left, Yao said to him: "In order to manage our country in a better way, I want to know how many years can I live from now on. Please ask God this question for me." Hou Yi promised him. Hou yi came back from God with ten magic arrows. He shot down nine suns, and the world returned to harmony. When Yao asked Hou Yi about the answer of his question, Hou Yi said: "God told me nothing. But I happened to see a 'life and death book' with your name on it. So I know the answer. But you know, I can't tell you because that's God's secret, and anyone who gives out God's secret will be burned by a thunder!" Yao was very angry, he shouted: "But you promised me, remember?" Hou Yi said: "Ooo-er, let's make some compromise. I can't tell you the answer directly, but I can tell you by my only precious magic arrow. I'll shoot the magic arrow several times on the ground, and of course the arrow will leave some holes on the ground. When you connect three holes with three line segments, you may get a triangle. The maximum number of similar triangles you can get means the number of years you can live from now on." (If the angles of one triangle are equal to the angles of another triangle respectively, then the two triangles are said to be similar.) Yao was not good at math, but he believed that he could find someone to solve this problem. Would you help the great ancient Chinese emperor Yao?
Input
There are multiple test cases, and the number of test cases is no more than 12. The first line of every test case is an integer n meaning that Hou Yi had shot the magic arrow for n times (2 < n <= 18). Then n lines follow. Each line contains two integers X and Y (-100 < X, Y < 100), the coordinate of a hole made by the magic arrow. Please note that one hole can be the vertex of multiple triangles. The input ends with n = 0.
Output
For each test case, print a line with an integer indicating the maximum number of similar triangles Yao could get.
Sample Input
3 1 1 6 5 12 10 4 0 0 1 1 2 0 1 -1 0
Sample Output
1 4
Source
题意:给你n个点,问最多有多少三角形相似!
暴力枚举!刚开始忘记去重了,否则三角形会重复算的!!!
dp[i][j]为最小的两个角为jiao[i]和jiao[j]的相似三角形有几个!!!
1 #include<stdio.h> 2 #include<math.h> 3 #include<algorithm> 4 using namespace std; 5 #define eps 1e-10 6 #define oo 100000000 7 #define pi acos(-1) 8 struct point 9 { 10 double x,y; 11 point(double _x = 0.0,double _y = 0.0) 12 { 13 x =_x; 14 y =_y; 15 } 16 point operator -(const point &b)const 17 { 18 return point(x - b.x, y - b.y); 19 } 20 point operator +(const point &b)const 21 { 22 return point(x +b.x, y + b.y); 23 } 24 double operator ^(const point &b)const 25 { 26 return x*b.y - y*b.x; 27 } 28 double operator *(const point &b)const 29 { 30 return x*b.x + y*b.y; 31 } 32 void input() 33 { 34 scanf("%lf%lf",&x,&y); 35 } 36 }; 37 38 int dcmp(double a) 39 { 40 if(fabs(a)<eps)return 0; 41 if(a>0)return 1; 42 else return -1; 43 } 44 45 bool operator ==(const point &a,const point &b) 46 { 47 return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0; 48 } 49 50 double dis(point a,point b) 51 { 52 return sqrt((a-b)*(a-b)); 53 } 54 55 double len(point a) 56 { 57 return sqrt(a*a); 58 } 59 60 double Angle(point a,point b) 61 { 62 double ans=acos((a*b)/len(a)/len(b)); 63 return ans; 64 } 65 66 bool cmp(point a,point b) 67 { 68 if(dcmp(a.x-b.x)==0)return a.y<b.y; 69 return a.x<b.x; 70 } 71 72 double jiao[8000]; 73 int dp[2500][2500]; 74 point P[200],p[200]; 75 int main() 76 { 77 78 int n,i,j,k; 79 while(~scanf("%d",&n)&&n) 80 { 81 for(i=0;i<n;i++) P[i].input(); 82 int ss=1; 83 sort(P,P+n,cmp); 84 p[0]=P[0]; 85 for(i=1;i<n;i++)//排除重复的点!! 86 { 87 if(p[ss-1]==P[i]) 88 continue; 89 p[ss++]=P[i]; 90 } 91 n=ss; 92 int cnt=0; 93 for(i=0;i<n;i++) 94 for(j=0;j<n;j++) 95 for(k=0;k<n;k++) 96 { 97 if(i!=j&&i!=k&&j!=k) 98 { 99 point v,w; 100 v=p[j]-p[i]; 101 w=p[k]-p[i]; 102 double ag=Angle(v,w); 103 if(dcmp(ag)>0) 104 jiao[cnt++]=ag; 105 } 106 } 107 sort(jiao,jiao+cnt); 108 cnt=unique(jiao,jiao+cnt)-jiao; 109 for(i=0;i<=cnt;i++) 110 for(j=0;j<=cnt;j++) 111 dp[i][j]=0; 112 for(i=0;i<n;i++) 113 for(j=i+1;j<n;j++) 114 for(k=j+1;k<n;k++) 115 { 116 point v,w; 117 double ag1,ag2,ag3; 118 v=p[j]-p[i]; 119 w=p[k]-p[i]; 120 if(dcmp(v^w)==0)continue;//排除共线情况,否则wa!! 121 ag1=Angle(v,w); 122 v=p[i]-p[j]; 123 w=p[k]-p[j]; 124 ag2=Angle(v,w); 125 v=p[i]-p[k]; 126 w=p[j]-p[k]; 127 ag3=Angle(v,w); 128 double aa[4]; 129 aa[0]=ag1;aa[1]=ag2;aa[2]=ag3; 130 sort(aa,aa+3); 131 int ii,jj; 132 for(int kk=0;kk<cnt;kk++) 133 { 134 if(dcmp(aa[0]-jiao[kk])==0)ii=kk; 135 if(dcmp(aa[1]-jiao[kk])==0){jj=kk;break;} 136 } 137 dp[ii][jj]++; 138 } 139 int ans=0; 140 for(i=0;i<cnt;i++) 141 for(j=i;j<cnt;j++) 142 if(dcmp(jiao[i])!=0) 143 ans=max(ans,dp[i][j]); 144 printf("%d\n",ans); 145 } 146 return 0; 147 }