当前位置:网站首页>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;
}

边栏推荐
- Protobuf and grpc
- Zzuli:1055 rabbit reproduction
- Code writing and playing method of tonybot humanoid robot at fixed distance
- NOI OPENJUDGE 1.5(23)
- Puzzle (016.4) domino effect
- Optical cat super account password and broadband account password acquisition
- Zzuli:1058 solving inequalities
- 光猫超级账号密码、宽带账号密码 获取
- [combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
- US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars
猜你喜欢
![[engine development] in depth GPU and rendering optimization (basic)](/img/71/abf09941eb06cd91784df50891fe29.jpg)
[engine development] in depth GPU and rendering optimization (basic)

Sword finger offer 28 Symmetric binary tree

Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text

Timecho of Tianmou technology completed an angel round financing of nearly 100 million yuan to create a native timing database of the industrial Internet of things

Talking about part of data storage in C language

Pyqt interface production (login + jump page)

adc128s022 ADC verilog设计实现

On MEM series functions of C language
![[ue4] HISM large scale vegetation rendering solution](/img/a2/2ff2462207e3c3e8364a092765040c.jpg)
[ue4] HISM large scale vegetation rendering solution

To improve efficiency or increase costs, how should developers understand pair programming?
随机推荐
adc128s022 ADC verilog设计实现
Output student grades
亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?
零拷贝底层剖析
7-1 positive integer a+b (15 points)
tonybot 人形机器人 首次开机 0630
Address book sorting
Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
mmdetection 学习率与batch_size关系
Dllexport et dllimport
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解
Zzuli:1052 sum of sequence 4
Luogu p5194 [usaco05dec]scales s solution
ShowMeBug入驻腾讯会议,开启专业级技术面试时代
My QT learning path -- how qdatetimeedit is empty
[graphics] hair simulation in tressfx
The latest M1 dedicated Au update Adobe audit CC 2021 Chinese direct installation version has solved the problems of M1 installation without flash back!
puzzle(016.4)多米诺效应
Puzzle (016.3) is inextricably linked
Tailing rushes to the scientific and Technological Innovation Board: it plans to raise 1.3 billion, and Xiaomi Changjiang is the shareholder