Codeforces 344B Simple Molecules
Description
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.
A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number.
Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.
Input
The single line of the input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 106) — the valence numbers of the given atoms.
Output
If such a molecule can be built, print three space-separated integers — the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print "Impossible" (without the quotes).
Sample Input
1 1 2
0 1 1
3 4 5
1 3 2
4 1 1
Impossible
题意:这道题告诉你3个节点的度数,也就是相邻两点的边的数目,例如:我们定义这三个顶点分别是a,b,c,设第一个点和第二个点之间的边的数目为x,第二个点与第三个点之间的边的数目为y,第三个点与第四个
点之间的边的数目为z,那么a = x + z, b = x + y, c = y + z;而且根据握手定理: 顶点度数之和为变得2倍,所以顶点度数和为偶数,而且两点见得边数不小于0. 有个疑点是为什么x = a +b - c?
1 /************************************************************************* 2 > File Name: cf.cpp 3 > Author: PrayG 4 > Mail: 5 > Created Time: 2016年07月10日 星期日 12时57分34秒 6 ************************************************************************/ 7 8 #include<iostream> 9 #include<cstdio> 10 #include<bits/stdc++.h> 11 #include<string> 12 using namespace std; 13 const int maxn = 200005; 14 int main() 15 { 16 int a,b,c; 17 cin >> a >> b >> c; 18 int x ,y,z; 19 int sum; 20 sum = a+ b + c; 21 x = a + b - c; 22 y = b + c - a; 23 z = a + c - b; 24 if(x < 0 || y < 0 || z < 0|| sum%2) 25 { 26 printf("Impossible\n"); 27 } 28 else 29 { 30 printf("%d %d %d\n",x/2,y/2,z/2); 31 } 32 return 0; 33 }