Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

各位靓仔,错在哪 ?

Posted by cxb24 at 2007-06-03 21:32:06 on Problem 1234
//#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator