当前位置:网站首页>B2020 points candy
B2020 points candy
2022-07-03 14:51:00 【Dega Altman】
Divide candy
Title Description
In a kindergarten , Yes 5 5 5 The numbers of the children are 1 , 2 , 3 , 4 , 5 1,2,3,4,5 1,2,3,4,5 They sat around a round table in their numbered order . They have some candy on them , Now they play a candy game . from 1 1 1 Children begin to , Divide your candy into 3 3 3 Share ( If there's extra candy , Just eat it immediately ), Keep one for yourself , The other two will be given to the two children next to him . next 2 , 3 , 4 , 5 2,3,4,5 2,3,4,5 Children No. 1 also do this . After the round , How many sweets are there in each child's hand .
Input format
a line , 5 5 5 Two separated by spaces int
Positive integer in range , At the beginning of the game 1 , 2 , 3 , 4 , 5 1,2,3,4,5 1,2,3,4,5 The number of sweets in children's hands .
Output format
2 2 2 That's ok , The first 1 1 1 Lines are separated by a space 5 5 5 It's an integer , It means after a round of game 1 , 2 , 3 , 4 , 5 1,2,3,4,5 1,2,3,4,5 The number of sweets in children's hands . The first 2 2 2 The row is an integer , Indicates the total number of sweets eaten during a round of the game .
Examples #1
The sample input #1
8 9 10 11 12
Sample output #1
11 7 9 11 6
6
Ideas
No difficulty , Just calculate according to the meaning of the title , If you don't understand , You can leave me a message below .
Code
#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;
}
边栏推荐
- 【7.3】146. LRU caching mechanism
- [graphics] real shading in Unreal Engine 4
- Qt—绘制其他东西
- Optical cat super account password and broadband account password acquisition
- Piwigo 2.7.1 sqli learning
- Zzuli:1056 lucky numbers
- 关于敏捷的一些概念
- Talking about part of data storage in C language
- NOI OPENJUDGE 1.4(15)
- 556. 下一个更大元素 III : 简单构造模拟题
猜你喜欢
To improve efficiency or increase costs, how should developers understand pair programming?
On MEM series functions of C language
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
[graphics] real shading in Unreal Engine 4
How to query the baby category of tmall on Taobao
Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
Tonybot humanoid robot starts for the first time 0630
The latest M1 dedicated Au update Adobe audit CC 2021 Chinese direct installation version has solved the problems of M1 installation without flash back!
Devaxpress: range selection control rangecontrol uses
C language to realize mine sweeping
随机推荐
NOI OPENJUDGE 1.6(09)
表单文本框的使用(一) 选择文本
Container of symfony
Find books ()
NOI OPENJUDGE 1.5(23)
Zzuli:1058 solving inequalities
Zzuli:1041 sum of sequence 2
pyQt界面制作(登录+跳转页面)
Bucket sorting in C language
[combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
Analysis of gene family characteristics - chromosome location analysis
Luogu p4047 [jsoi2010] tribal division solution
Simulation of LS -al command in C language
C language to implement a password manager (under update)
.NET六大设计原则个人白话理解,有误请大神指正
7-9 one way in, two ways out (25 points)
[ue4] material and shader permutation
Get permissions dynamically
[ue4] HISM large scale vegetation rendering solution
C language fcntl function