当前位置:网站首页>[day_040421] calculate candy
[day_040421] calculate candy
2022-07-26 06:11:00 【On the Bank of Anhe Bridge】
Calculate candy
Title source
Cattle from : Calculate candy
Title Description
A,B,C Three people are good friends , Everyone has some candy in his hand , We don't know how many sweets each of them has , But we know the following information :
A - B, B - C, A + B, B + C. These four values . Each letter represents the number of sweets each person has .
Now we need to calculate how many sweets each person has in his hand through these four values , namely A,B,C. There is guaranteed to be at most one set of integers A,B,C Meet all problem setting conditions .
Input description
Enter as one line , altogether 4 It's an integer , Respectively A - B,B - C,A + B,B + C, Space off . The range is -30 To 30 Between ( Closed interval ).
Output description
Output as a line , If there is an integer that satisfies A,B,C Then output... In sequence A,B,C, Space off , There is no space at the end of the line . If such an integer does not exist A,B,C, The output No
Example 1
Input
1 -2 3 4
Output
2 1 3
Thought analysis
- According to the method of solving ternary linear equations in Mathematics , Addition and subtraction , Work out separately A、B、C Value
- because B There is more than one solution , So we use two methods to find B Value comparison of , There is only one solution
- The number of candies owned by three people is greater than or equal to 0
Code display
#include<iostream>
using namespace std;
int main()
{
int n1, n2, n3, n4;
int a, b1, b2, c;
// Cycle through multiple data
while (cin >> n1 >> n2 >> n3 >> n4)
{
if (n3 < 0 || n4 < 0)
{
cout << "No";
continue;
}
// The number of sweets is not decimal
if ((n1 + n3) % 2 != 0 || (n2 + n4) % 2 != 0 || (n3 - n1) % 2 != 0 || (n4 - n2) % 2 != 0)\
{
cout << "No";
continue;
}
a = (n1 + n3) / 2;
b1 = (n2 + n4) / 2;
b2 = (n3 - n1) / 2;
c = (n4 - n2) / 2;
if (b1 != b2 || a < 0 || b1 < 0 || c < 0)
{
cout << "No";
}
else
{
cout << a << " " << b1 << " " << c;
}
}
}
边栏推荐
- H. Take the Elevator 贪心
- Ganglia installation and deployment process
- 语法泛化三种可行方案介绍
- TPS Motion(CVPR2022)视频生成论文解读
- Detailed explanation of the whole process of coding's pressure measurement operation
- WebAPI整理
- [highly available MySQL solution] centos7 configures MySQL master-slave replication
- Implementation of PHP multitask second timer
- Flex layout
- [(SV & UVM) knowledge points encountered in written interview] ~ phase mechanism
猜你喜欢

Database SQL language practice

【Day_06 0423】不要二

Age is a hard threshold! 42 years old, Tencent level 13, master of 985, looking for a job for three months, no company actually accepted!

Kingbasees SQL language reference manual of Jincang database (6. Expression)

Sequential action localization | fine grained temporal contrast learning for weak supervised temporal action localization (CVPR 2022)

1.12 Web开发基础

Knowledge precipitation I: what does an architect do? What problems have been solved

flex布局

Mysql45 talking about infrastructure: how is an SQL query executed?

Leetcode:940. How many subsequences have different literal values
随机推荐
L. Link with Level Editor I dp
【Day_03 0420】字符串中找出连续最长的数字串
Docking wechat payment (II) unified order API
【(SV && UVM) 笔试面试遇到的知识点】~ phase机制
Matlab vector and matrix
【BM2 链表内指定区间反转】
对接微信支付(二)统一下单API
Calling mode and execution sequence of JS
Flex layout
基于消防GIS系统的智慧消防应用
Mysql45 talking about infrastructure: how is an SQL query executed?
【Day_05 0422】统计回文
Optical quantum milestone: 3854 variable problems solved in 6 minutes
Oc/swift Technology Download File (breakpoint continuation AFN download file alamofire Download File native download) (source code)
"Recursive processing of subproblems" -- judging whether two trees are the same tree -- and the subtree of another tree
ament_cmake生成ROS2库并链接
[(SV & UVM) knowledge points encountered in written interview] ~ phase mechanism
How to divide the disks under the devices and drives in win10 new computer
Interview difficulties: difficulties in implementing distributed session, this is enough!
【Day_02 0419】排序子序列