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;
}
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;
}
相关文章推荐
- CUIT ACM Personal Training 11.27(FM)D - Yaroslav and Permutations
- CUIT ACM Personal Training 11.27(FM)F - Polo the Penguin and Strings
- CUIT ACM Personal Training 11.27(FM)G - Increase and Decrease
- CUIT ACM Personal Training 11.27(FM)B - IQ Test
- CUIT ACM Personal Training 11.27(FM)C - Cupboards
- CUIT ACM Personal Training 11.27(FM) H - Slightly Decreasing Permutations
- CUIT ACM Personal Training 11.27(FM)J - Building Permutation
- CUIT ACM Personal Training 11.27(FM)A - Buggy Sor
- Codeforces Round #178 (Div. 2)---A. Shaass and Oskols
- codeforces A. Shaass and Oskols 题解
- A. Shaass and Oskols
- ACM 水题 Wallace and His Pet
- angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)
- HDU 5874 2016 ACM/ICPC Asia Regional Dalian Online 1007 Friends and Enemies
- HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)
- [Training Video - 5] [Groovy Script Test Step - Collections, Exceptions] HashSet and Hashtable
- 杭电ACM 第106题 Tick and Tick
- HDOJ1029 Ignatius and the Princess IV【AC率最高的一题】-----武科大ACM暑期集训队选拔赛3题
- B. Mashmokh and ACM
- A Personal Selection of Books on E lectromagnetics and Computational E lectromagnetics---David B. Davidson