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 |
H-O-H#include <iostream> #include <stdio.h> using namespace std; int main() { int N; while(scanf("%d", &N) > 0){ if(N == 0) break; //printf("%d\n", N); int k; scanf("%d\n", &k); k--; bool lr[33];//0: l 1: r for(int i = 0; i < N; i++){ char tmp; scanf("%c\n", &tmp); if(tmp == 'L') lr[i] = 0; else lr[i] = 1; } //for(int i = 0; i < N; i++) cout << lr[i] << " "; cout << endl; int no = N; bool get[33] = {0}; int lastball = 0, cs = 0, curball = k; while(1){ if(!get[curball]){ no--; get[curball] = 1; } if(no == 0){ printf("Classmate %d got the ball last after %d tosses.\n", curball+1, cs+1); break; } int nextball; if(lr[curball] == 0){ nextball = (lastball+N-1)%N; if(nextball == curball){ nextball = (nextball+N-1)%N; } } else{ nextball = (lastball+1)%N; if(nextball == curball){ nextball = (nextball+1)%N; } } lr[curball] = !lr[curball]; lastball = curball; curball = nextball; cs++; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator