zoj 2164 Hanafuda Shuffle

来源:互联网 发布:火炬之光2mac版下载 编辑:程序博客网 时间:2024/06/15 16:04
/*用栈直接模拟非常方便! */#define LOCAL#include<iostream>#include<stack>using namespace std;int main(){#ifdef LOCAL       freopen("input.txt","r",stdin);       freopen("output.txt","w",stdout);#endif            int n,r,p,q,i;    while(cin>>n>>r,n)    {         stack<int> a,b,c;         for(i=1;i<=n;i++)              a.push(i);         while(r--)         {                cin>>p>>q;                p--;                while(p--)                {                      b.push(a.top());                      a.pop();                          }                while(q--)                {                      c.push(a.top());                      a.pop();                          }                          while(!b.empty())                {                      a.push(b.top());                      b.pop();                           }                while(!c.empty())                {                      a.push(c.top());                      c.pop();                           }         }         cout<<a.top()<<endl;                         }    return 0;}

原创粉丝点击