- 題意(原題,NOIP2017提高組Day1):
- n個人圍成一圈,逆時針給出每個人的朝向與名字。
- 從第一個人開始,給出m個操作,表示在這個人的位置處向左/右走x個人的位置,求最終位置。
- n,m<=100000
- 思路:
- 暴力模擬,向外+向左=+x,向內+向右=+x,其餘-x。每個操作((now+/-x)+n%n)即可。
- 代碼:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
struct person
{
int cx;
char name[11];
person()
{
cx=0;
memset(name,0,sizeof(name));
}
}a[110000];
int main()
{
int n,m,now=0;
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)
scanf("%d %s",&a[i].cx,a[i].name);
while(m--)
{
int x,y,opt;
scanf("%d%d",&x,&y);
if(a[now].cx==1&&x==0)opt=1;
if(a[now].cx==1&&x==1)opt=-1;
if(a[now].cx==0&&x==0)opt=-1;
if(a[now].cx==0&&x==1)opt=1;
now=((now+y*opt)+n)%n;
}
printf("%s\n",a[now].name);
return 0;
}