哈理工OJ 2111 Apple(简单模拟)

来源:互联网 发布:广告算法工程师面试题 编辑:程序博客网 时间:2024/04/29 10:17

题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2111

Apple
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 114(71 users) Total Accepted: 75(69 users) Rating: Special Judge: No
Description
There is a table, on which some plates were put in a circle. Some apples were put in the plates.

Let's play a game.For each plate, separate the apples into two parts. For example if a plate containing M apples, put M/2 apples into the left-hand plate and the rest to the righthand plate. Note that if M is a odd number, then M/2 equals (M-1)/2. Plates are numbered from 1 to N in counter-clockwise. The left-hand plate is the plate whose number is smaller. The left-hand plate of plate numbered 1 is the plate numbered N. Given the number of apples in each plate(1,2,...N), output the the number of apples in each plate when game is over.

Input
The input contains multiple test case. The first line of each case contains a integer N, the number of plates on the table, followed by N integers a1, a2, …, aN representing the number of apples in the plates(1,2,…N).

1<=N<=10000, 1<=ai<=100.

Output
For each test case print the number of apples in each plate(from numbered 1 to N) when game is over.

Sample Input
5
1 2 3 4 5
10
1 2 3 4 5 6 7 8 9 10
Sample Output
4 2 3 4 2
6 2 3 4 5 6 7 8 9 5
Source
ACM-ICPC黑龙江省第九届大学生程序设计竞赛选拔赛(2)

【中文题意】n个人围成1个圈,1的左边是n,就是每个人有一定的苹果数,每个人的苹果的一半给左边的人,剩下的给右边的人,问你最后每个人有多少苹果。
【思路分析】直接模拟就好了。
【AC代码】

#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<stack>#include<queue>using namespace std;#define LL long longint a[10005],re[10005];int main(){    int n;    while(~scanf("%d",&n))    {        for(int i=1;i<=n;i++)        {            scanf("%d",&a[i]);        }        re[1]=a[2]/2+a[n]-a[n]/2;        for(int i=2;i<=n-1;i++)        {            re[i]=(a[i-1]-a[i-1]/2)+a[i+1]/2;        }        re[n]=a[n-1]-a[n-1]/2+a[1]/2;        for(int i=1;i<n;i++)        {            printf("%d ",re[i]);        }        printf("%d\n",re[n]);    }    return 0;}
1 0