当前位置:网站首页>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;
}
边栏推荐
- 1017 a divided by B (20 points)
- Zzuli:1055 rabbit reproduction
- Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
- 2021-10-16 initial programming
- Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
- Protobuf and grpc
- 7-9 one way in, two ways out (25 points)
- 从书本《皮囊》摘录的几个句子
- Zzuli:1053 sine function
- 数学常数表 by q779
猜你喜欢
Showmebug entered Tencent conference, opening the era of professional technical interview
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
[opengl] advanced chapter of texture - principle of flowmap
Detailed explanation of four modes of distributed transaction (Seata)
Use of constraintlayout
How to color ordinary landscape photos, PS tutorial
tonybot 人形机器人 定距移动 代码编写玩法
[ue4] material and shader permutation
[graphics] hair simulation in tressfx
复合类型(自定义类型)
随机推荐
pyQt界面制作(登录+跳转页面)
Talking about part of data storage in C language
Tonybot humanoid robot starts for the first time 0630
Zzuli:1048 factorial table
Niuke: crossing the river
分布式事务(Seata) 四大模式详解
[graphics] efficient target deformation animation based on OpenGL es 3.0
puzzle(016.4)多米诺效应
Yolov5进阶之九 目标追踪实例1
[opengl] face pinching system
retrofit
[ue4] material and shader permutation
C language STR function
556. The next larger element III
牛客 BM83 字符串變形(大小寫轉換,字符串反轉,字符串替換)
C language DUP function
NOI OPENJUDGE 1.3(06)
Code writing and playing method of tonybot humanoid robot at fixed distance
Luogu p4047 [jsoi2010] tribal division solution
dllexport和dllimport