POJ 1244 Slots of Fun(计算几何)
很简单的一题,数据 很小,直接暴力的。但是也是写也好久,有几个数,没算好。。。一次CE,一次PE,3Y。
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <cmath> 6 using namespace std; 7 #define eps 1e-8 8 #define zero(x) (((x) > 0?(x):-(x))<eps) 9 int o[200]; 10 struct point 11 { 12 double x,y; 13 } p[1001]; 14 double dis(point p1,point p2) 15 { 16 return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y); 17 } 18 int judge(int i,int j,int k) 19 { 20 if(zero(dis(p[i],p[j])-dis(p[j],p[k]))&&zero(dis(p[i],p[j])-dis(p[i],p[k]))) 21 return 1; 22 else 23 return 0; 24 } 25 char str[1001]; 26 int main() 27 { 28 int n,i,j,k,num = 1,len,flag; 29 double d; 30 p[0].x = 0; 31 p[0].y = 0; 32 for(i = 2; i <= 12; i ++) 33 { 34 d = (i-1)*1.0*sqrt(3.0)*2.0/3.0/(i-1); 35 p[num].x = -(i-1)*1.0*sqrt(3.0)/3.0; 36 p[num].y = i-1; 37 num ++; 38 for(j = 1; j < i; j ++) 39 { 40 p[num].x = p[num-1].x + d; 41 p[num].y = i-1; 42 num ++; 43 } 44 } 45 while(scanf("%d",&n)!=EOF) 46 { 47 if(n == 0) break; 48 memset(o,0,sizeof(o)); 49 scanf("%s",str); 50 len = strlen(str); 51 flag = 0; 52 for(i = 0; i < len; i ++) 53 { 54 for(j = i+1; j < len; j ++) 55 { 56 if(str[i] == str[j]) 57 for(k = j+1; k < len; k ++) 58 { 59 if(str[j] == str[k]) 60 { 61 if(judge(i,j,k)) 62 { 63 flag = 1; 64 o[str[i]+0] ++; 65 } 66 } 67 } 68 } 69 } 70 if(!flag) 71 { 72 printf("LOOOOOOOOSER!\n"); 73 continue; 74 } 75 for(i = 0;i <= 128;i ++) 76 { 77 if(o[i]) 78 { 79 for(j = 1;j <= o[i];j ++) 80 printf("%c",i); 81 } 82 } 83 printf("\n"); 84 } 85 return 0; 86 }