| ||||||||||
| 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"stdio.h"
#include"iostream.h"
int pass[30];
int want[30];
int main(){
//freopen("in.txt","r",stdin);
int result,k,n,hand,from,j;
long unsigned i;
char c;
for(;;){
cin>>n;//scanf("%d",&n);
if(n==0)break;
cin>>hand;//scanf("%d",&hand);
hand--;
for(j=0;j<n;j++){
cin>>c;//scanf(" %c",&c);
if(c=='L')want[j]=-1;
else if(c=='R') want[j]=1;
pass[j]=0;
}//getchar();
from=0,result=2,pass[0]=1,pass[hand]=1;
for(i=2;result<n;i++){
k=(from+want[hand]+n)%n;
if(k==hand){
k=(k+want[hand]+n)%n;
}
want[hand]=want[hand]*(-1);
if(pass[k]==0){
pass[k]=1;
result++;
}
from=hand;
hand=k;
}
cout<<"Classmate "<<hand+1<<" got the ball last after "<<i-1<<" tosses."<<endl;
//printf("Classmate %d got the ball last after %d tosses.\n",hand+1,i-1);
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator