codeforces-344bSimple molecules
| Time Limit: 1000MS |
|
Memory Limit: 262144KB |
|
64bit IO Format: %i64d &%i64u |
Submit Status Description Mad scientist Mike is busy carrying out experiments in chemistry. Today He'll attempt to join three atoms into one molecule. A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom have 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 is 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 this 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 is multiple solutions, output any of them. If There is no solution, print "impossible" (without the quotes). Sample Input Input1 1 2 Output0 1 1 Input3 4 5 Output1 3 2 Input4 1 1 OutputImpossible
Hint The first sample corresponds to the first figure. There is no bonds between atoms 1 and 2 in this case. The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms. The third sample corresponds to the third figure. There is no solution, because a atom cannot form bonds with itself. The configuration in the fourth are impossible as each atom must has at least one atomic bond. Suppose a, B, C represent the valence of an atom. Suppose X, y, z represent chemical bonds between atoms. First x+y+z must be an even number, otherwise there is no solution. Then a three-dimensional equation can be listed, consisting of 3 equations, which can be used to find the unique solution. The only limiting condition for judging the solution is that no negative numbers can occur.
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath>using namespace std; int main () { //freopen ("D://imput.txt", "R", stdin); int A, B, C, X, Y, Z, Temp1, Temp2; while (Cin >> a >> b >> c) { Temp1 = a + B + C; Temp2 = B-a + C; if (Temp1 & 1) { cout << "impossible" << Endl; Continue; } if (Temp2 & 1) { cout << "impossible" << Endl; Continue; } x = A-(Z = c-(y = TEMP2/2)); if (x < 0 | | Y < 0 | | Z < 0) { cout << "impossible" << Endl; Continue; } cout << x << "<< y <<" "<< z << endl; } return 0;}
|