CodeFroces 解题报告
1.题目描述
A. Shaass and Oskols
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 a**i 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, …, a**n, (0 ≤ a**i ≤ 100).
The third line contains an integer m, (0 ≤ m ≤ 100). Each of the next m lines contains two integers x**i and y**i. The integers mean that for the i-th time Shaass shoot the y**i-th (from left) bird on the x**i-th wire, (1 ≤ x**i ≤ n, 1 ≤ y**i). It’s guaranteed there will be at least y**i birds on the x**i-th wire at that moment.
Output
On the i-th line of the output print the number of birds on the i-th wire.
Examples
input
Copy
5
10 10 10 10 10
5
2 5
3 13
2 12
1 13
4 6
output
Copy
0
12
5
0
16
input
Copy
3
2 4 1
1
2 2
output
Copy
3
0
3
2. 解题思路
根据题目分析,这道题是一个标准的模拟题(没有啥算法,按题目要求模拟就行了),题目需要特判一下当操作数为第1行和最后一行的时候,该行的前i只鸟,该行的后n-i只鸟都会飞走,除此以外,就按题目要求的模拟即可
3. 代码
// Problem: A. Shaass and Oskols
// Contest: Codeforces - Codeforces Round #178 (Div. 2)
// URL: https://codeforces.com/contest/294/problem/A
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
vector<int>a;
while(t--){
int t1;
cin>>t1;
a.push_back(t1);
}
int m;
cin>>m;
while(m--){
int x,y;
cin>>x>>y;
if(x==1){
a[x]+=a[x-1]-y;
a[x-1]=0;
}
else if(x==a.size()){
a[x-2]+=y-1;
a[x-1]=0;
}
else{
a[x-2]+=y-1;
a[x]+=a[x-1]-y;
a[x-1]=0;
}
}
for(int i=0;i<a.size();i++){
cout<<a[i]<<endl;
}
return 0;
}