当前位置:网站首页>B2020 分糖果
B2020 分糖果
2022-07-03 14:49:00 【迪迦 • 奥特曼】
分糖果
题目描述
某个幼儿园里,有 5 5 5 位小朋友编号依次为 1 , 2 , 3 , 4 , 5 1,2,3,4,5 1,2,3,4,5 他们按照自己的编号顺序围坐在一张圆桌旁。他们身上有若干糖果,现在他们玩一个分糖果游戏。从 1 1 1 号小朋友开始,将自己的糖果均分成 3 3 3 份(如果有多余的糖果,就自己立即吃掉),自己留一份,其余两份分给和他相邻的两个小朋友。接着 2 , 3 , 4 , 5 2,3,4,5 2,3,4,5 号小朋友也这样做。问一轮结束后,每个小朋友手上分别有多少糖果。
输入格式
一行, 5 5 5 个用空格隔开的 int 范围内的正整数,分别是游戏开始时 1 , 2 , 3 , 4 , 5 1,2,3,4,5 1,2,3,4,5 号小朋友手里糖果的数量。
输出格式
2 2 2 行,第 1 1 1 行是用一个空格隔开的 5 5 5 个整数,表示一轮游戏结束后 1 , 2 , 3 , 4 , 5 1,2,3,4,5 1,2,3,4,5 号小朋友手里糖果的数量。第 2 2 2 行是一个整数,表示一轮游戏过程中吃掉的糖果的总数。
样例 #1
样例输入 #1
8 9 10 11 12
样例输出 #1
11 7 9 11 6
6
思路
没有难度,就是按着题意算就可以,如果有不懂的,可以在下方给我留言。
代码
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int r[5];
int total = 0;
for (int i = 0; i < 5; i++) {
cin >> r[i];
}
for (int i = 0; i < 5; i++) {
total += r[i] % 3;
if (i == 4) {
r[0] += r[i] / 3;
}
else {
r[i + 1] += r[i] / 3;
}
if (i == 0) {
r[4] += r[i] / 3;
}
else {
r[i-1] += r[i] / 3;
}
r[i] /= 3;
}
for (int i = 0; i < 5; i++) {
cout << r[i]<< " ";
}
cout << endl << total << endl;
return 0;
}

边栏推荐
- 洛谷P5536 【XR-3】核心城市 题解
- C language memory function
- 提高效率 Or 增加成本,开发人员应如何理解结对编程?
- Simulation of LS -al command in C language
- 表单文本框的使用(一) 选择文本
- Sub GHz wireless solution Z-Wave 800 Series zg23 SOC and zgm230s modules
- Zhejiang University Edition "C language programming (4th Edition)" topic set reference ideas set
- Tensor 省略号(三个点)切片
- ShowMeBug入驻腾讯会议,开启专业级技术面试时代
- Zzuli:1041 sum of sequence 2
猜你喜欢
随机推荐
Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
Zzuli:1045 numerical statistics
Luogu p5536 [xr-3] core city solution
Zzuli:1041 sum of sequence 2
[engine development] in depth GPU and rendering optimization (basic)
Tonybot Humanoïde Robot Infrared Remote play 0630
Sword finger offer 28 Symmetric binary tree
[ue4] material and shader permutation
远程服务器后台挂起 nohup
Zzuli:1048 factorial table
Tonybot humanoid robot starts for the first time 0630
Zzuli:1055 rabbit reproduction
Zzuli:1058 solving inequalities
Showmebug entered Tencent conference, opening the era of professional technical interview
ASTC texture compression (adaptive scalable texture compression)
基因家族特征分析 - 染色体定位分析
分布式事务(Seata) 四大模式详解
tonybot 人形机器人 红外遥控玩法 0630
Zzuli:1046 product of odd numbers
cpu飙升排查方法





![[ue4] geometry drawing pipeline](/img/30/9fcf83a665043fe57389d44c2e16a8.jpg)


![洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解](/img/89/da1a3a38e02671628f385de0f30369.png)