Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一次过了,留个代码,供人参考#include<iostream> #include<math.h> using namespace std; int t ; char val[100]; int visited[100]; bool in[30]; typedef struct { char v; double x; double y; }mynode; mynode node[100]; int main() { freopen("in.txt","r",stdin); int i,j; while(scanf("%d",&t)&&t) { memset(in,0,sizeof(in)); scanf("%s",val); for(i=0;i<t;i++) { for(j=0;j<=i;j++) { node[i*(i+1)/2+j].v=val[i*(i+1)/2+j]; node[i*(i+1)/2+j].x=i*1.0/2.0*(-1)+j; node[i*(i+1)/2+j].y=i*sqrt(3.0)/2; } } memset(visited,0,sizeof(visited)); double x1,y1,x2,y2,x3,y3;int num=0;char now; bool flag1=false,flag2=false,flag3=false,flag=false; flag1=true; while(flag1==true) { for(i=0;i<strlen(val);i++) { flag1=false,flag2=false,flag3=false; if(visited[i]==false) { now=node[i].v; x1=node[i].x; y1=node[i].y; visited[i]=true; flag1=true; break; } } for(i=i+1;i<strlen(val);i++) { if(visited[i]==false&&node[i].v==now) { x2=node[i].x; y2=node[i].y; flag2=true; visited[i]=true; break; } } for(i=i+1;i<strlen(val);i++) { if(visited[i]==false&&node[i].v==now) { x3=node[i].x; y3=node[i].y; visited[i]=true; flag3=true; break; } } if(flag1==true&&flag2==true&&flag3==true) { double temp1,temp2,temp3; temp1=(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3); temp2=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3); temp3=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); double sub1=temp1-temp2; if(sub1<0) sub1*=-1; double sub2=temp2-temp3; if(sub2<0) sub2*=-1; double sub3=temp1-temp3; if(sub3<0) sub3*=-1; if(sub1<0.0000000001&&sub2<0.0000000001&&sub3<0.0000000001) { in[now-'a']=true; flag=true; } } } if(flag==false) printf("LOOOOOOOOSER!"); else { for(i=0;i<30;i++) if(in[i]==true) printf("%c",i+'a'); } printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator