Codeforce 294A - Shaass and Oskols (模拟)
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.
![](http://codeforces.com/predownloaded/52/f3/52f39ff5e49f07bf581c627767c492086842649c.png)
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 thei-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.
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 yi birds on the xi-th wire at that moment.
On the i-th line of the output print the number of birds on the i-th wire.
5
10 10 10 10 10
5
2 5
3 13
2 12
1 13
4 6
0
12
5
0
16
3
2 4 1
1
2 2
3
0
3
题解:莫得撒子好说的读懂题意直接模拟
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <vector> 6 #include <cstdlib> 7 #include <iomanip> 8 #include <cmath> 9 #include <ctime> 10 #include <map> 11 #include <set> 12 using namespace std; 13 #define lowbit(x) (x&(-x)) 14 #define max(x,y) (x>y?x:y) 15 #define min(x,y) (x<y?x:y) 16 #define MAX 100000000000000000 17 #define MOD 1000000007 18 #define pi acos(-1.0) 19 #define ei exp(1) 20 #define PI 3.141592653589793238462 21 #define INF 0x3f3f3f3f3f 22 #define mem(a) (memset(a,0,sizeof(a))) 23 typedef long long ll; 24 ll gcd(ll a,ll b){ 25 return b?gcd(b,a%b):a; 26 } 27 const int N=105; 28 const int mod=1e9+7; 29 bool flag=0; 30 int a[N]={0}; 31 int main() 32 { 33 std::ios::sync_with_stdio(false); 34 int n,m,x,y; 35 cin>>n; 36 for(int i=1;i<=n;i++){ 37 cin>>a[i]; 38 } 39 if(n==1) { 40 cin>>m; 41 if(m==0){//这种情况要考虑一下 42 cout<<a[1]<<endl; 43 return 0; 44 } 45 cin>>x>>y; 46 cout<<0<<endl; 47 return 0; 48 } 49 cin>>m; 50 for(int i=1;i<=m;i++){ 51 cin>>x>>y; 52 if(x==1){ 53 a[x+1]+=a[x]-y; 54 a[x]=0; 55 } 56 else if(x==n){ 57 a[x-1]+=y-1; 58 a[x]=0; 59 } 60 else { 61 a[x+1]+=a[x]-y; 62 a[x-1]+=y-1; 63 a[x]=0; 64 } 65 } 66 for(int i=1;i<=n;i++) 67 cout<<a[i]<<endl; 68 return 0; 69 }