CUIT ACM Personal Training 11.27(FM)E - Shaass and Oskols
来源:互联网 发布:seo学校 编辑:程序博客网 时间:2024/06/05 14:37
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
510 10 10 10 1052 53 134 62 121 13
0125160
32 4 112 2
303
题解:这个题就是一个简单的模拟,一开始在N个电线上分别有a1,a2,a3....an只鸟,然后猎人会挑中其中一只打,打死一直以后,在那只鸟的左边的鸟都会飞到前一条电线上,右边的鸟都会飞到后一条电线上。当往前飞的鸟或者往后飞的鸟发现没有电线时,就会飞走,最后输出N电线上鸟的个数。
这个题目我们可以用一个数组搞定,首先扫描猎人打的是第n根电线上的第m只鸟,那么左边就加上m-1,右边就加上a[n]-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)E - Shaass and Oskols
- CUIT ACM Personal Training 11.27(FM)A - Buggy Sor
- 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)J - Building Permutation
- 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) H - Slightly Decreasing Permutations
- A. Shaass and Oskols
- codeforces 294A Shaass and Oskols
- codeforces A. Shaass and Oskols 题解
- CodeForces 294A Shaass and Oskols
- Codeforces Round #178 (Div. 2)---A. Shaass and Oskols
- Codeforces Round #178 (Div. 2) / 294A Shaass and Oskols(模拟)
- 排列组合 Shaass and Lights:CodeForces
- Shaass and Painter Robot : CodeForces294D
- 四川省ACM竞赛(2013)---E - Naive and Silly Muggles
- CDH5.X完全卸载步骤
- java io 学习小结之输入流InputStream
- 由一个语句引出的关于C的变量和常量的相关知识
- 几个简单java基础的例子
- 新浪短地扯PHP实例
- CUIT ACM Personal Training 11.27(FM)E - Shaass and Oskols
- POJ 1543 Perfect Cubes
- ubuntu 14.04/14.10下安装VMware Workstation 11图文教程
- 怎样解决Birt的中文乱码
- AM335x是如何通过网络实现远程桌面连接
- Setting up Ubuntu (currently 12.04.2) to compile FreeWRL
- Linux输入子系统框架分析及输入设备驱动编程
- 验证手机格式,不合格的给出提示,并定位焦点
- 监听audio是否播放完