hdu1194(水)

来源:互联网 发布:上海华腾软件怎么样 编辑:程序博客网 时间:2024/05/01 16:09

题目链接Beat the Spread!


给定两个分数a,b的和与差的绝对值(a,b∈N),如果能求出a,b就直接输出,否则输出impossible


注意int型计算(a+b)/2和(a-b)/2自动取整

因此要判断a,b是否同是奇数或者同是偶数,否则我们也是计算不出来的

#include <iostream>#include <stdio.h>using namespace std;int main(){    //freopen("in.txt","r",stdin);    int x,y,a,b;    int T;    scanf("%d",&T);    while(T--){        scanf("%d%d",&a,&b);        if(a<b)printf("impossible\n");        else if((a-b)&1)printf("impossible\n");        else {            x=(a+b)/2;            y=(a-b)/2;            printf("%d %d\n",x,y);        }    }    return 0;}




0 0
原创粉丝点击