CodeForces - 344B Simple Molecules (模拟题)

CodeForces - 344B

Simple 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 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 ab 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

Input

1 1 2

Output

0 1 1

Input

3 4 5

Output

1 3 2

Input

4 1 1

Output

Impossible

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.

假设A、B、C代表原子的化合价

假设x、y、z代表原子之间的化学键

首先x+y+z一定为偶数,否则不可能有解。

那么可以列出一个三元一次的方程组,由3个方程组成,可以求出唯一解。

判断有解的唯一限制条件是:不能出现负数。

#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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-29 10:48:22

CodeForces - 344B Simple Molecules (模拟题)的相关文章

Codeforces 344B Simple Molecules

#include<bits/stdc++.h> using namespace std; int main() { int a,b,c; scanf("%d%d%d",&a,&b,&c); int ab=a+b-c,bc=b+c-a,ac=a+c-b; if(ab>=0&&bc>=0&&ac>=0&&ab%2==0&&bc%2==0&&ac%2==0)

Codeforces 48C The Race 模拟题

题目链接:点击打开链接 题意: 给定n个加油站,一辆车由A点跑到B点,每个100m有一个加油站,每开100m需要10升油. 在每个车站会检查一下油量,若车子若开不到下一个加油站则加x升油. 开始有x升油 下面给出加油的记录. 问下一次加油在哪一站.若答案唯一输出具体哪站. 油箱容量无限 思路: 水模拟.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

CodeForces - 344D Alternating Current (模拟题)

CodeForces - 344D Alternating Current Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! H

CodeForces 681C Heap Operations (模拟题,优先队列)

题意:给定 n 个按顺序的命令,但是可能有的命令不全,让你补全所有的命令,并且要求让总数最少. 析:没什么好说的,直接用优先队列模拟就行,insert,直接放入就行了,removeMin,就得判断一下队列是不是空的,然后再考虑getMin,这个是不是对应的值,如果队列中首元素比它大,那么就加上一个, 如果相等直接取出,如果小于就不断取队列中最小元素. 代码如下: #include <bits/stdc++.h> using namespace std; char s[15], t[30]; v

CodeForces - 427B (模拟题)

Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of t

hdu 2778 LCR 模拟题

模拟题都是水题.但是要认真读题,逻辑上要认真考虑,争取一次AC. Description LCR is a simple game for three or more players. Each player starts with three chips and the object is to be the last person to have any chips. Starting with Player 1, each person rolls a set of three dice.

18002 Z-Scan 模拟题

18002 Z-Scan 时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: 不限定 Description Z-Scan is a method to scan data in a square matrix(矩阵). Fig.1 shows Z-Scan. Here, the number stands for the scan sequence number of the element. Our question is very sim

又是一道模拟题吧!

题目如下:This cheeseburger you don't need Description Yoda: May the Force be with you. Master Yoda is the oldest member of the Jedi Council. He conducts preparatory classes of little Younglings up to the moment they get a mentor. All Younglings adore mas

Codeforces Beta Round 2 A题:Winner

题目传送门 这道题我开始准备使用map+stable_sort来做,但是无论是map或是unorder_map,都会改变输入的顺序,导致某一组答案错误. 所以我们可以使用map来进行纯模拟的操作. 首先,在输入的同时把最终各个人的分数加起来,然后找到最大值. 其次,再次模拟一遍游戏,当找到第一个达到m且最终的分数也大于等于m的人,输出即可. 12345678910111213141516171819202122232425262728293031323334 #define rep(i,a,n)