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

边栏推荐
- Luogu p5194 [usaco05dec]scales s solution
- Use of constraintlayout
- C language STR function
- Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in
- [graphics] hair simulation in tressfx
- How to color ordinary landscape photos, PS tutorial
- dllexport和dllimport
- Zzuli:1044 failure rate
- 远程服务器后台挂起 nohup
- [engine development] in depth GPU and rendering optimization (basic)
猜你喜欢

dllexport和dllimport

Bucket sorting in C language

Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million

tonybot 人形机器人 定距移动 代码编写玩法

QT program font becomes larger on computers with different resolutions, overflowing controls

零拷贝底层剖析

cpu飙升排查方法

Adc128s022 ADC Verilog design and Implementation

分布式事务(Seata) 四大模式详解

远程服务器后台挂起 nohup
随机推荐
Four data flows and cases of grpc
Detailed explanation of four modes of distributed transaction (Seata)
Luogu p5194 [usaco05dec]scales s solution
Piwigo 2.7.1 sqli learning
【7.3】146. LRU缓存机制
[graphics] efficient target deformation animation based on OpenGL es 3.0
QT program font becomes larger on computers with different resolutions, overflowing controls
Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
retrofit
Puzzle (016.3) is inextricably linked
Use of form text box (I) select text
Protobuf and grpc
How to color ordinary landscape photos, PS tutorial
How does vs+qt set the software version copyright, obtain the software version and display the version number?
[engine development] rendering architecture and advanced graphics programming
Fundamentals of PHP deserialization
Zzuli:1047 logarithmic table
Use of constraintlayout
7-1 positive integer a+b (15 points)
406. 根据身高重建队列