/*
用栈直接模拟
非常方便!
*/
#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;
}
zoj 2164 Hanafuda Shuffle
最新推荐文章于 2018-08-14 15:53:04 发布