|
|
вернуться в форумWhy my program still WA?Please help me!Thank you! #include<stdio.h> #define max 1001 int n,start,fly,note[max][3],use[max],airport[max]; void tidy() { int i,j; for(i=0;i<max;i++) for(j=0;j<3;j++) note[i][j]=0; for(i=1;i<max;i++)airport[i]=0; for(i=1;i<max;i++)use[i]=0; fly=0; } void init() { int i,a,b; scanf("%d%d",&n,&start); for(i=1;i<n;i++) { scanf("%d%d",¬e[i][1],¬e[i][2]); } } void statn() { int i,j; for(i=1;i<n;i++) for(j=1;j<3;j++) use[note[i][j]]++; } void find() { int i,j,k,s,p; p=0; for(i=1;i<=n;i++) if((i!=start)&&(use[i]==1)) { p=1;if(airport[i])s=0;else s=1; for(j=1;j<n;j++) if(((note[j][1]==i)||(note[j][2]==i))&&(!note[j][0])) { if(note[j][1]==i)k=note[j][2];else k=note[j][1]; note[j][0]=1;use[k]++; if(s&&(airport[k]>i))airport[k]=i; break; } use[i]=0; } if(p)find(); } void work() { statn(); find(); fly=airport[start]; } void out() { if(fly) {printf("First player wins flying to airport %d\n",fly);} else{printf("First player loses\n");} } void main() { tidy(); init(); work(); out(); } I'v Ac now!!!!!!!! > #include<stdio.h> > > #define max 1001 > > int n,start,fly,note[max][3],use[max],airport[max]; > > void tidy() > { > int i,j; > for(i=0;i<max;i++) > for(j=0;j<3;j++) > note[i][j]=0; > for(i=1;i<max;i++)airport[i]=0; > for(i=1;i<max;i++)use[i]=0; > fly=0; > } > > void init() > { > int i,a,b; > scanf("%d%d",&n,&start); > for(i=1;i<n;i++) > { > scanf("%d%d",¬e[i][1],¬e[i][2]); > } > } > > void statn() > { > int i,j; > for(i=1;i<n;i++) > for(j=1;j<3;j++) > use[note[i][j]]++; > } > > void find() > { > int i,j,k,s,p; > p=0; > for(i=1;i<=n;i++) > if((i!=start)&&(use[i]==1)) > { > p=1;if(airport[i])s=0;else s=1; > for(j=1;j<n;j++) > if(((note[j][1]==i)||(note[j][2]==i))&&(!note[j][0])) > { > if(note[j][1]==i)k=note[j][2];else k=note[j][1]; > note[j][0]=1;use[k]++; > if(s&&(airport[k]>i))airport[k]=i; > break; > } > use[i]=0; > } > if(p)find(); > } > > void work() > { > statn(); > find(); > fly=airport[start]; > } > > void out() > { > if(fly) > {printf("First player wins flying to airport %d\n",fly);} > else{printf("First player loses\n");} > } > > void main() > { > tidy(); > init(); > work(); > out(); > } |
|
|