4

codeforces 344B - Simple Molecules

 3 years ago
source link: https://zxs.io/article/171
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Simple Molecules

       题意就是给出3个原子的化学价,然后组成一个分子,要保证这个分子是稳定的,如果你还记得高中化学知识的话这个很容易理解,然后让你求出1-2  2-3 1-3 号原子之间有几条键, 这里我分别用ta tb tc 表示, 用数学的方法表示出来的话就是a = tc + tb; b = ta+tc; c = ta + tb;可能有多种情况,只要输出一种即可。

      我们随便找其中一个原子,然后从0开始枚举它到b原子有多少键,根据上面的式子,可以计算出到c原子的键,然后就可以知另外两个原子间的键值,做一次判断即可,无需判断a = tc + tb; b = ta+tc; c = ta + tb; 因为计算工程中就用到了其中两个等式,保证其一定成立。 还有就是无法组成分子的情况,我们只要没找到满足条件的三个值就输出"Impossible"。

//cf 334B
//2013-09-19-15.57
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    int a, b, c;
    while (scanf("%d %d %d", &a, &b, &c) != EOF)
    {
        int flag = 1;
        for (int i = 0; i <= a; i++)
        {
            int tb = i, tc = a-i;
            if (tb > c)
                continue;
            int ta = c - tb;
            if (b == ta + tc)
            {
                printf("%d %d %d\n", tc, ta, tb);
                flag = 0;
                break;
            }
        }
        if (flag)
            puts("Impossible");
    }
    return 0;
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK