程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> zzu--2014年11月16日月賽 A題

zzu--2014年11月16日月賽 A題

編輯:C++入門知識

zzu--2014年11月16日月賽 A題


1228: Simple Molecules

Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 22 Solved: 8
[Submit][Status][Web Board]

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, c (1 <= a, b, c <= 1^6) ----- 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 23 4 54 1 1

Sample Output

0 1 11 3 2Impossible

HINT

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.

Source

CF


題意:就是看能不能成化學鍵


思路:先判斷能不能成化學鍵(用一個fun函數調用),然後再存1、2, 2、3, 3、1之間的bonds,存bonds時可以先判斷前兩個原子的化學鍵數!


AC代碼:

#include 
#include 
#include 
#define max3(a,b,c) max(max(a,b),c)
using namespace std;

int fun(int a[], int b[])
{
	b[0] = a[0], b[1] = a[1], b[2] = a[2];
	sort(b, b+3);
	if(b[0]+b[1] < b[2]) return 0;
	else if(b[0]+b[1] >= b[2] && (b[0]+b[1]+b[2])%2==0) return 1;
	return 0;
}

int main()
{
	int a[3], b[3];
	while(scanf("%d %d %d", &a[0], &a[1], &a[2])!=EOF)
	{
		int t = fun(a, b);
		int bond[3]={0};
		if(t == 0)
		{
			printf("Impossible\n");
			continue;
		}
		else if(t == 1)
		{
			while(a[0]+a[1]!=a[2])
			{
				a[0]--;a[1]--;bond[0]++;
			}
			bond[1] = a[1]; bond[2] = a[0];
		}
		printf("%d %d %d\n", bond[0], bond[1], bond[2]);
	} 
	return 0;
}




  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved