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

题目链接: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 long

int 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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值