Description

Polycarp has guessed three positive integers \(a\), \(b\) and \(c\). He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: \(a+b\), \(a+c\), \(b+c\) and \(a+b+c\).

You have to guess three numbers \(a\), \(b\) and \(c\) using given numbers. Print three guessed integers in any order.

Pay attention that some given numbers \(a\), \(b\) and \(c\) can be equal (it is also possible that \(a=b=c\)).

Input

The only line of the input contains four positive integers \(x_{1}\),\(x_{2}\),\(x_{3}\),\(x_{4}\)(\(2\)≤\(x_{i}\)≤\(10^{9}\)) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number \(x_{1}\),\(x_{2}\),\(x_{3}\),\(x_{4}\).

Output

Print such positive integers \(a\), \(b\) and \(c\) that four numbers written on a board are values \(a+b\), \(a+c\), \(b+c\) and \(a+b+c\) written in some order. Print \(a\), \(b\) and \(c\) in any order. If there are several answers, you can print any. It is guaranteed that the answer exists.

Examples

Input1:

3 6 5 4

Output1:

2 1 3

Input2:

40 40 40 60

Output2:

20 20 20

Input3:

201 101 101 200

Output3:

1 100 100

Solution

简化版题意:

有三个正整数\(a\), \(b\), \(c\), 现在给定\(x_{1}\) \(=\) \(a + b\), \(x_{2}\) \(=\) \(a +c\), \(x_{3}\) \(=\) \(b + c\), \(x_{4}\) \(=\) \(a + b + c\)。 请求出\(a\), \(b\), \(c\)分别是多少。

这是一道数论题。

我们先整理一下题面告诉我们的信息:

  1. \(a\)、\(b\)、\(c\)是三个正整数;

  2. 我们会输入4个乱序的数字:\(x1\)、\(x2\)、\(x3\)、\(x4\);

  3. \(x_{1}\) = \(a\) + \(b\) , \(x_{2}\) = \(a\) + \(c\) , \(x_{3}\) = \(b\) + \(c\) , \(x_{4}\) = \(a\) + \(b\) + \(c\)。

∵\(a\)、\(b\)、\(c\)均>\(0\).

∴\(x_{4}\)是这四个数中最大的数。

至于如何求出\(a\)、\(b\)、\(c\),则可以:

用\(x_{4} - x_{1}\)得到\(c\),用\(x_{4} - x_{2}\)得到\(b\),用\(x_{4} - x_{3}\)得到\(a\),最后按顺序输出这三个数即可。

注意:我们需要开一个数组\(x\)[]来存储\(x_{1}\)、\(x_{2}\)、\(x_{3}\)、\(x_{4}\),因为这样便于我们排序(可以直接调用\(c++\)库函数\(sort\),但要开头文件\(algorithm\)),而且可以更好地帮助我们寻找到\(a\)、\(b\)、\(c\)。

Code

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>//头文件准备 using namespace std;//使用标准名字空间 inline int gi()//快速读入,不解释
{
int f = 1, x = 0;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
{
x = x * 10 + c - '0';
c = getchar();
}
return f * x;
} int a, b, c, x[5];//a、b、c和x数组的意义同分析 inline void init()//分别输入这四个数
{
x[1] = gi(), x[2] = gi(), x[3] = gi(), x[4] = gi();
} inline void solve()//将x数组从小到大排序
{
sort(x + 1, x + 1 + 4);//1和4是指从x[1]到x[4]从小到大排序
} inline void output()//输出的自函数
{
printf("%d %d %d\n", x[4] - x[1], x[4] - x[2], x[4] - x[3]);//分别输出a、b、c。
} int main()//进入干净整洁的主函数
{
init();//输入
solve();//排序解决问题
output();//输出
return 0;//养成return 0的好习惯
}

题解【CodeForces1154A】Restoring Three Numbers的更多相关文章

  1. CF1154A Restoring Three Numbers 题解

    Content 已知有三个正整数 \(a,b,c\),现在给出 \(a+b,a+c,b+c,a+b+c\)(不保证有序)的值,试求出 \(a,b,c\). 数据范围:\(2\leqslant a+b, ...

  2. leetcode题解2. Add Two Numbers

    题目: You are given two non-empty linked lists representing two non-negative integers. The digits are ...

  3. 《LeetBook》LeetCode题解(2):Add Two Numbers [M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  4. LeetCode题解之Find All Numbers Disappeared in an Array

    1.题目描述 2.问题分析 使的 A[i] = i+1 ,最后检查不满足这个条件的i+1 .即为缺失的值. 3.代码 vector<int> findDisappearedNumbers( ...

  5. LeetCode 题解之Add Two Numbers II

    1.题目描述 2.分析 首先将链表翻转,然后做加法. 最后将结果链表翻转. 3.代码 ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { Lis ...

  6. LeetCode题解之Add two numbers

    1.题目描述 2.题目描述 题目思路可以参考合并单链表的思路,定义一个全局 进位标志,如果两个数值相加得到需要进位,则将进位标志置为1 . 3.代码 ListNode* addTwoNumbers(L ...

  7. leetCode题解之Self Dividing Numbers

    1.题目描述 2.题目分析 简单题目,只要挨个判断该数是不是满足条件即可. 3.代码 vector<int> selfDividingNumbers(int left, int right ...

  8. LeetCode题解 #2 Add Two Numbers

    题目大意:使用链表表示的两个整数,计算出其和,以同样的形式返回. Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 ...

  9. 题解 CF171A 【Mysterious numbers - 1】

    又是愚人节题目qwq-- 说一下题意吧: 把第1个数翻转后加第二个数 具体思路: 1.定义变量,进行输入 int a,b; cin>>a>>b; 2.定义一个变量c,作为存储第 ...

随机推荐

  1. 剑指offer-面试题29-顺时针打印矩阵-矩阵

    /* 题目: 输入一个矩阵,按照从外到内顺时针的顺序依次打印每一个数字. */ /* 思路: 1.将打印矩阵看作是打印一个个从外向内的环. 2.每一个环都有一个起始节点,起始节点的坐标*2小于行数和列 ...

  2. Bell数

    事实上,\[e^{(e^t-1)x}=\sum_{k=0}^{\infty}\frac{B_k(x)}{k!}.\]\[B_n(x)=x\sum_{k=1}^{n}\binom{n-1}{k-1}B_ ...

  3. jQuery---京东轮播图

    京东轮播图 有个计数的,点右边,计数增加,判断计数是否超过总的长度,超过设置计数为0,再设置当前的图片动画,兄弟的图片动画 左边点击同理,计数是--,判断计数是否等于-1,等于则reset计数为总长度 ...

  4. 18新生赛 4. Deal

    题目描述:双十一过后,syx发现自己快要吃土了.但是机智的他决定理财.他预测了将来n天的比特币行情,发现有涨有跌,有跌有涨.手里的钱只要在比特币的浪潮中经历沉浮,低价收入,高价卖出,就可以轻易割到别人 ...

  5. C语言 goto

    C语言 goto 功能:无条件跳转.不推荐使用 案例 #include <stdio.h> int main() { // 函数跳转.循环跳转 // 创建标志位开始 // 无条件跳转到En ...

  6. PATA-1151 LCA in a Binary Tree

    题意:根据前序和中序建立树,寻找两个点的LCA. 我在之前的博客中写了关于LCA的多种求法. https://www.cnblogs.com/yy-1046741080/p/11505547.html ...

  7. GNU Radio的hello world(转)

    运行GNU Radio 需要注意的是,如果您的项目不需要用到硬件源和硬件池的话,直接使用Shell运行GRC是没有问题的.但是需要用到硬件源和硬件池的话,请记得使用管理员权限运行GRC,否则项目在执行 ...

  8. Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type

    问题描述 将项目挂载到 Myeclipse 的 tomcat 上,启动 tomcat ,报错“Initialization of bean failed; nested exception is ja ...

  9. 用C#调用外部DLL

    1.有时候需要用C#调用外部的dll,例如c++写的dll,首先需要保证dll的编译环境与本项目的环境是相同的,例如都是x86位或者x64位 2.调用声明和dll内的声明一致: function Te ...

  10. @Cacheable注解不生效原因

    因为@Cacheable注解应用了AOP动态代理,生成代理类,判断缓存中是否存在该key,如果不存在则调用被代理类的标有@Cachable注解的方法,否则不执行. 所以当类A的方法a调用方法b(标有@ ...