poj1978

简单题

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
using namespace std;

#define maxn 100

int n, r;
int f[maxn], g[maxn];

void work(int p, int c)
{
for (int i = 0; i < c; i++)
g[i]
= f[p + i];
for (int i = p - 1; i > 0; i--)
f[i
+ c] = f[i];
for (int i = 0; i < c; i++)
f[i
+ 1] = g[i];
}

int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%d%d", &n, &r), n | r)
{
for (int i = 1; i <= n; i++)
f[i]
= n - i + 1;
for (int i = 0; i < r; i++)
{
int p, c;
scanf(
"%d%d", &p, &c);
work(p, c);
}
printf(
"%d\n", f[1]);
}
return 0;
}

你可能感兴趣的:(poj)