您的位置:首页 > 产品设计 > UI/UE

CUIT ACM Personal Training 11.27(FM)E - Shaass and Oskols

2016-11-29 16:15 387 查看
E - Shaass and Oskols
Time Limit:2000MS     Memory Limit:262144KB     64bit
IO Format:
%I64d & %I64u

Description

Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to nfrom
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
integers a1, 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 yibirds
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 Input

Input
510 10 10 10 1052 53 134 62 121 13

Output
0125160

Input
32 4 112 2

Output
303

题解:这个题就是一个简单的模拟,一开始在N个电线上分别有a1,a2,a3....an只鸟,然后猎人会挑中其中一只打,打死一直以后,在那只鸟的左边的鸟都会飞到前一条电线上,右边的鸟都会飞到后一条电线上。当往前飞的鸟或者往后飞的鸟发现没有电线时,就会飞走,最后输出N电线上鸟的个数。

这个题目我们可以用一个数组搞定,首先扫描猎人打的是第n根电线上的第m只鸟,那么左边就加上m-1,右边就加上a
-m,特判一下在两边的临界情况就可以了。

AC代码如下:

#include<bits/stdc++.h>
using namespace std;

int num[105];
int n,m,x,y;

int main()
{
cin>>n;
for(int i=1; i<=n; i++) cin>>num[i];
cin>>m;
for(int i=1; i<=m; i++)
{
cin>>x>>y;
if(x==1){num[x+1]+=num[x]-y;}
else if(x==n){num[x-1]+=y-1;}
else{num[x-1]+=y-1;num[x+1]+=num[x]-y;}
num[x]=0;
}
for(int i=1; i<=n; i++)
cout<<num[i]<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: