codeforces A. Shaass and Oskols 题解
2014-05-01 20:33
846 查看
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 numberi - 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 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
模拟鸟飞的过程, 暴力法了。
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 numberi - 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 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
模拟鸟飞的过程, 暴力法了。
#include <vector> #include <string> #include <iostream> using namespace std; #define FR(i, n) for (i = 0; i < n; i++) void ShaassandOskols() { int n = 0, ythBird = 0, xthWire = 0; cin>>n; vector<int> wires(n); int i = 0; FR (i, n) cin>>wires[i]; cin>>n; FR (i, n) { cin>>xthWire>>ythBird; if (xthWire > 1) wires[xthWire-2] += ythBird-1; if (xthWire < (int)wires.size()) wires[xthWire] += wires[xthWire-1] - ythBird; wires[xthWire-1] = 0; } FR(i, wires.size()) { cout<<wires[i]<<endl; } }
相关文章推荐
- codeforces #199 C. Cupboard and Balloons 题解
- codeforces Sereja and Dima 题解
- Codeforces Round #365 (Div. 2)Mishka and Divisors 题解。 DP
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) 题解(A-E)
- Codeforces Round #384 (Div. 2) A. Vladik and flights【思维】水题
- 743C. Vladik and fractions codeforces
- Codeforces#305-C-Soldier and Cards-暴力模拟-deque
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) ABCD题解
- 【转】Codeforces GoodBye2015 New Year and Three Musketeers Codeforces 611E(贪心)
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
- Codeforces Round #354 (Div. 2) C. Vasya and String
- Codeforces Round #384 B. Chloe and the sequence
- Codeforces Round #421 (Div. 1):B. Mister B and PR Shifts 思维,乱搞
- Codeforces Round #258 (Div. 2)题解(ALL)
- codeforces Vasya and Petya's Game(筛选法)
- 【Codeforces Round 263 (Div 2)D】【树形DP】Appleman and Tree 树上割k个黑点为k块的方案数
- codeforces Masha and geometric depression(set模拟,等比数列)
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(分形)
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)