Codeforces Round #200 (Div. 2)B. Simple Molecules
来源:互联网 发布:域名续费查询 编辑:程序博客网 时间:2024/06/06 04:23
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.
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.
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).
1 1 2
0 1 1
3 4 5
1 3 2
4 1 1
Impossible
The first sample corresponds to the first figure. There are 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 an atom cannot form bonds with itself.
The configuration in the fourth figure is impossible as each atom must have at least one atomic bond.
解题报告
此题为数学问题,输入的三个数(a,b,c)分别等于
x+y=a;
x+z=b;
y+z=c;
2z=a+b-c;
于是就可以求出x,y,z了,代码如下
#include<stdio.h>int main() { int a, b, c ,flag=0; int x, y, z; scanf("%d%d%d",&a,&b,&c); if ((a+b-c) % 2) { printf("Impossible\n"); flag=1; } else { x = (a+b-c)/2; y = a - x; z = b - x; if ( x < 0 || y < 0 || z < 0) { printf("Impossible\n"); flag=1; } } if(!flag) printf("%d %d %d\n",x,z,y); return 0;}
- Codeforces Round #200 (Div. 2)B. Simple Molecules
- codeforces 344B - Simple Molecules
- Codeforces 344B Simple Molecules
- [Codeforces] 344B - Simple Molecules
- CodeForces - 344B Simple Molecules (模拟题)
- Codeforces Round #316 (Div. 2)570B Simple Game(脑洞)
- Codeforces Round #316 (Div. 2) -B-Simple Game-水题
- 570B. Simple Game Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2) B. Simple Game
- Codeforces Round #316 (Div. 2) B. Simple Game
- Codeforces Round #316 (Div. 2) B. Simple Game
- Codeforces Round #316 (Div. 2) B. Simple Game (模拟)
- B. Simple Game-----(Codeforces Round #316 (Div. 2))
- Codeforces Round #316 (Div. 2) B. Simple Game
- B. Simple Molecules
- B. Simple Game( Codeforces Round #316 (Div. 2) 简单题)
- CF#200 div2 B Simple Molecules(Brute force)
- Codeforces Round #131 (Div. 2) A B
- 灰度直方图均衡化(下)
- 《UNIX环境高级编程》笔记--sync、fsync和fdatasync函数
- 第一个grails连接mongodb数据的程序。
- CSipSimple程序之基本功能(一)
- 四层和七层负载均衡的区别
- Codeforces Round #200 (Div. 2)B. Simple Molecules
- log4j的使用及参考
- 汉诺塔简单图形设计思想3(C)
- linux 安装配置VNC
- Windows Azure 底层架构
- Java位运算在程序设计中的使用:位掩码(BitMask)
- 4.1
- 查看數據庫中所有表的屬性及使用情況
- ubuntu的命令行启动