[Simulation] toy puzzle

Original title Portal

Thinking


From a pure analog flood problem NOIP improve the group, I do not know why was beaten high-performance labels on some valley (malicious score QAQ?), Do not care, will be able to direct violence AC,(Dafa is good violence, violence, security and peace)
This question is added as long as promising counterclockwise along the line is reduced, by the ring, can be simulated with an array, note the time index n on the line die, further, do not appear when a negative Save index.

The rest is blind water code QAQ, escape ~

Code


#include<iostream>
using namespace std;

struct node 
{
    int head;
    string name;
}a[100005];
int n,m,x,y,now;

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].head>>a[i].name;
    }
    for(int i=1;i<=m;i++)
    {
        cin>>x>>y;
        if(a[now].head==0&&x==0)now=(now+n-y)%n;//加n是为了防止产生负数,下同
        else if(a[now].head==0&&x==1)now=(now+y)%n;
        else if(a[now].head==1&&x==0)now=(now+y)%n;
        else if(a[now].head==1&&x==1)now=(now+n-y)%n;
    }
    cout<<a[now].name<<endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/gongdakai/p/11031411.html