Content

已知有三个正整数 \(a,b,c\),现在给出 \(a+b,a+c,b+c,a+b+c\)(不保证有序)的值,试求出 \(a,b,c\)。

数据范围:\(2\leqslant a+b,a+c,b+c,a+b+c\leqslant 10^9\)。

Solution

肯定地,如果是无序的话,那么我们肯定要先对这四个值排序,得到:

\[\begin{cases}x_1=a+b\\x_2=a+c\\x_3=b+c\\x_4=a+b+c\end{cases}
\]

那么,运用加减消元,我们就可以得到:

\[\begin{cases}a=x_4-x_3\\b=x_4-x_2\\c=x_4-x_1\end{cases}
\]

直接输出这三个值就好了。

Code

int x[7];

int main() {
_for(i, 1, 4) getint(x[i]);
sort(x + 1, x + 5);
int a = x[4] - x[1], b = x[4] - x[2], c = x[4] - x[3];
writeint(a), putchar(' '), writeint(b), putchar(' '), writeint(c);
return 0;
}

CF1154A Restoring Three Numbers 题解的更多相关文章

  1. 题解【CodeForces1154A】Restoring Three Numbers

    Description Polycarp has guessed three positive integers \(a\), \(b\) and \(c\). He keeps these numb ...

  2. CF55D Beautiful numbers 题解

    题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...

  3. Hdoj 1905.Pseudoprime numbers 题解

    Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1 ...

  4. Hdoj 1058.Humble Numbers 题解

    Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...

  5. [LeetCode] Add Two Numbers题解

    Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. Th ...

  6. poj 1995 Raising Modulo Numbers 题解

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6347   Accepted: ...

  7. CF1265B Beautiful Numbers 题解

    Content 给定一个 \(1\sim n\) 的排列,请求出对于 \(1\leqslant m\leqslant n\),是否存在一个区间满足这个区间是一个 \(1\sim m\) 的排列. 数据 ...

  8. CF1157A-Reachable Numbers题解

    原题地址 题目大意:有一个函数\(f(x)\),效果是将\(x+1\)后,去掉末尾所有的\(0\),例如: \(f(599)=6\),因为\(599+1=600→60→6\) \(f(7)=8\),因 ...

  9. CF359D:Pair of Numbers——题解

    https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...

随机推荐

  1. C++构造函数写法

    笔记 class complex{ public: complex (double r = 0, double i = 0) : re(r), im(i) {} private: double re, ...

  2. PaintHouse II

    // // Created by Administrator on 2021/7/27. // #ifndef C__TEST01_PAINTHOUSE_HPP #define C__TEST01_P ...

  3. Codeforces 1290F - Making Shapes(数位 dp)

    Codeforces 题面传送门 & 洛谷题面传送门 数位 dp 好题. 首先,由于是凸包,一但向量集合确定,凸包的形态肯定就已经确定了.考虑什么样的向量集合能够组成符合条件的凸包,我们假设第 ...

  4. 洛谷 P7154 - [USACO20DEC] Sleeping Cows P(dp)

    Portal 题意: 给出两个序列 \(a_1,a_2,\dots,a_n\),\(b_1,b_2,\dots,b_n\),\(i\) 与 \(j\) 能匹配当且仅当 \(a_i\leq b_j\). ...

  5. 用Rsync实现windows下同步linux服务器的数据

    一:环境 1.服务端:Red Hat Enterprise Linux Server release 6.4 (Santiago) 2.客户端:windows7旗舰版64位 3.同步对象:测试数据 4 ...

  6. LearnPython_week3

    函数说明 1 # -*- coding:utf-8 -*- 2 # Author:Wong Du 3 4 5 ###函数, 6 # 能避免代码重复, 7 # 方便代码修改等操作 8 def wong( ...

  7. 普通用户iptables规则持久化,开机自动恢复

    本文档对于docker环境下并不适用,docker环境的iptables持久化请参考https://www.cnblogs.com/wiseo/p/15000745.html 添加iptables规则 ...

  8. kafka安装(单机版)

    一.安装kafka(单机版) 因为现在的kafka安装包都自带zookeeper,所以如果是安装本地单机版kafka,不需要额外去安装zookeeper,使用自带的就可以了. 1.下载kafka 2. ...

  9. Docker学习(五)——Docker仓库管理

    Docker仓库管理     仓库(Repository)是集中存放镜像的地方. 1.Docker Hub       目前Docker官方维护了一个公共仓库Docker Hub.大部分需求都可以通过 ...

  10. centos7安装Docker详细步骤(无坑版教程)

    一.安装前必读 在安装 Docker 之前,先说一下配置,我这里是Centos7 Linux 内核:官方建议 3.10 以上,3.8以上貌似也可. 注意:本文的命令使用的是 root 用户登录执行,不 ...