A. Shaass and Oskols
2013-04-13 08:55
375 查看
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from
top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols
sitting on the i-th wire.
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the i-th wire). Consequently all the birds on the i-th
wire to the left of the dead bird get scared and jump up on the wire number i - 1, if there exists no upper wire they fly away. Also all
the birds to the right of the dead bird jump down on wire number i + 1, if there exists no such wire they fly away.
Shaass has shot m birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the
shots.
Input
The first line of the input contains an integer n, (1 ≤ n ≤ 100).
The next line contains a list of space-separated integersa1, a2, ..., an, (0 ≤ ai ≤ 100).
The third line contains an integer m, (0 ≤ m ≤ 100).
Each of the next m lines contains two integers xi and yi.
The integers mean that for the i-th time Shaass shoot the yi-th
(from left) bird on the xi-th
wire, (1 ≤ xi ≤ n, 1 ≤ yi).
It's guaranteed there will be at least yi birds
on the xi-th
wire at that moment.
Output
On the i-th line of the output print the number of birds on the i-th
wire.
Sample test(s)
input
output
input
output
解题说明:此题只需要记住状态转移即可
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int n,i,m,t;
int pos,up;
int a[101];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&m);
for(t=0;t<m;t++)
{
scanf("%d %d",&pos,&up);
if(pos>1)
{
a[pos-2]+=up-1;
}
if(pos<n)
{
a[pos]+=a[pos-1]-up;
}
a[pos-1]=0;
}
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
return 0;
}
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from
top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols
sitting on the i-th wire.
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the i-th wire). Consequently all the birds on the i-th
wire to the left of the dead bird get scared and jump up on the wire number i - 1, if there exists no upper wire they fly away. Also all
the birds to the right of the dead bird jump down on wire number i + 1, if there exists no such wire they fly away.
Shaass has shot m birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the
shots.
Input
The first line of the input contains an integer n, (1 ≤ n ≤ 100).
The next line contains a list of space-separated integersa1, a2, ..., an, (0 ≤ ai ≤ 100).
The third line contains an integer m, (0 ≤ m ≤ 100).
Each of the next m lines contains two integers xi and yi.
The integers mean that for the i-th time Shaass shoot the yi-th
(from left) bird on the xi-th
wire, (1 ≤ xi ≤ n, 1 ≤ yi).
It's guaranteed there will be at least yi birds
on the xi-th
wire at that moment.
Output
On the i-th line of the output print the number of birds on the i-th
wire.
Sample test(s)
input
5 10 10 10 10 10 5 2 5 3 13 2 12 1 13 4 6
output
0 12 5 0 16
input
3 2 4 1 1 2 2
output
3 0 3
解题说明:此题只需要记住状态转移即可
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int n,i,m,t;
int pos,up;
int a[101];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&m);
for(t=0;t<m;t++)
{
scanf("%d %d",&pos,&up);
if(pos>1)
{
a[pos-2]+=up-1;
}
if(pos<n)
{
a[pos]+=a[pos-1]-up;
}
a[pos-1]=0;
}
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
return 0;
}
相关文章推荐
- codeforces A. Shaass and Oskols 题解
- CUIT ACM Personal Training 11.27(FM)E - Shaass and Oskols
- Codeforces Round #178 (Div. 2)---A. Shaass and Oskols
- Codeforces294B - Shaass and Bookshelf(贪心)
- 排列组合 Shaass and Lights:CodeForces - 294C
- Codeforces Round #178 (Div. 2) B .Shaass and Bookshelf
- [CF 294D]Shaass and Painter Robot解题报告
- 【Cf #178 A】Shaass and Lights(组合数)
- Codeforces Round #178 (Div. 2) B. Shaass and Bookshelf 【动态规划】0-1背包
- Shaass and Painter Robot : CodeForces294D
- codeforces 294B B. Shaass and Bookshelf(dp)
- Codeforces Round #178 (Div. 2) C. Shaass and Lights 【组合数学】
- Codeforces Round #178 (Div. 2) B Shaass and Bookshelf
- CodeForces 294C - Shaass and Lights 统计
- Codeforces Round #178 (Div. 2) B .Shaass and Bookshelf
- Codeforces Round #178 (Div. 2) C. Shaass and Lights
- C. Shaass and Lights
- B. Shaass and Bookshelf DP
- 15.11 The checked and unchecked statements
- VOIP 架构和技术(VOIP Architecture and Technologies)