当前位置: 代码迷 >> 综合 >> poj1234 Ball Toss
  详细解决方案

poj1234 Ball Toss

热度:11   发布时间:2024-01-12 05:22:54.0

直接模拟就行了, 就是题意有一点难懂


/*author: birdstorm*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>#define MAXN 1005
#define N 105
#define INF 1<<30
#define eps 1.0e-10#define For(i,m,n) for(i=(m);i<n;i++)
#define MAX(x,y) (x)>(y)?(x):(y)
#define MIN(x,y) (x)<(y)?(x):(y)main()
{int i, j, n, k, cnt, p, last, next, d[33], vis[33];char c[2];while(scanf("%d",&n),n){scanf("%d",&k); k--;For(i,0,n){vis[i]=0;scanf("%s",c);d[i]=c[0]=='L'?-1:1;}cnt=0; p=n; last=0;while(1){if(!vis[k]) vis[k]=1, p--;next=(d[k]+last+n)%n;if(next==k) next=(k+d[k]+n)%n;d[k]=-d[k];cnt++;if(!p) break;last=k; k=next;}printf("Classmate %d got the ball last after %d tosses.\n",k+1,cnt);}return 0;
}