zoukankan      html  css  js  c++  java
  • B. Simple Molecules

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output
     

    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).

    Examples
    input
    1 1 2
    output
    0 1 1
    input
    3 4 5
    output
    1 3 2
    input
    4 1 1
    output
    Impossible
    Note

    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.

    水题 求3个原子是否能构成一个分子使化学键和法。

    总共的化学键为(a+b+c)/2个,则只要判断各原子间化学键是否成立即可。

    附AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main(){
     5     int a,b,c;
     6     cin>>a>>b>>c;
     7     int t=(a+b+c)/2;
     8     int ans=0;
     9     int a1,a2,a3;
    10     int flag=0;
    11     for(int i=1;i<a;i++){
    12         a1=i,a3=a-a1,a2=t-a;
    13         if(a1+a2==b&&a2+a3==c){
    14             flag=1;
    15             break;
    16         }
    17     }
    18     if(flag==0){
    19         for(int i=1;i<b;i++){
    20         a1=i,a2=b-a1,a3=t-b;
    21         if(a1+a3==a&&a2+a3==c){
    22             flag=1;
    23             break;
    24         }
    25         }
    26     }
    27     if(flag==0){
    28         for(int i=1;i<c;i++){
    29         a3=i,a2=c-a3,a1=t-c;
    30         if(a1+a3==a&&a2+a1==b){
    31             flag=1;
    32             break;
    33         }
    34         }
    35     }
    36     if(flag&&a1>=0&&a2>=0&&a3>=0){
    37         cout<<a1<<" "<<a2<<" "<<a3<<endl;
    38     }
    39     else{
    40         cout<<"Impossible"<<endl;
    41     }
    42     return 0;
    43 } 
  • 相关阅读:
    Netty源码解析与实战
    什么是序列化id?
    关于idea下tomcat输出日志的问题
    利用jstack 找到异常代码
    mysql 异常 Lock wait timeout exceeded; try restarting transaction;expc=java.sql.SQLExcept
    Spark-Hadoop、Hive、Spark 之间是什么关系?(转)
    转(数据分析的意义)
    按位取反~100=-101
    知识总汇
    前端(以Vue为例)webpack打包后dist文件包如何部署到django后台中
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5908591.html
Copyright © 2011-2022 走看看