zoukankan      html  css  js  c++  java
  • CF552-Div3-A. Restoring Three Numbers

    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).

    题意:给你三个数,这三个数分别是a+b,a+c,b+c,a+b+c(无序);求出a,b,c.(a>0,b>0,c>0)
    题解:存进数组,sort以后,输出x4-x1,x4-x2,x4-x3(any order).x4是四个数中最大的数,可得出x4=a+b+c.那么其他三个数就是a+b,a+c,b+c.
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main(){
    	int a[5];
    	for(int i=1;i<=4;i++) cin>>a[i];
    	sort(a+1,a+1+4);
    	printf("%d %d %d
    ",a[4]-a[1],a[4]-a[2],a[4]-a[3]);
    	return 0;
    }
    
  • 相关阅读:
    Pick-up sticks
    The Doors
    Intersecting Lines
    Segments
    TOYS
    Palindrome
    Distinct Substrings
    Milk Patterns
    Musical Theme
    JavaScript基于时间的动画算法
  • 原文地址:https://www.cnblogs.com/-yjun/p/10727216.html
Copyright © 2011-2022 走看看