HDOJ 1194 Beat the Spread!

【题意】:给出两个数 m n,第一个数是另外两个数a b的和,第二个数是a b的差的绝对值(absolute difference)。输出这两个数a b,大的在前。

【思路】:大的数等于 (m+n)/2,小的等于m-大的。

【注意】:impossible的判断。分两种,一种是m<n,一种是m+n为奇数的情况。如果m+n为奇数,则a b不存在。

【AC代码】:

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
    int T = 0;
    cin >> T;
    getchar();
    while (T--)
    {
        int m = 0, n = 0;
        cin >> m >> n;
        if (m < n || 0 != (m+n)%2)
        {
            cout << "impossible" << endl;
            continue;
        }
        else
        {
            int a = 0, b = 0;
            a = (m+n)/2;
            b = m - a;
            if (a > b)
                cout << a << " " << b << endl;
            else
                cout << b << " " << a << endl;
        }
    }
    return 0;
}
时间: 2024-12-03 07:41:39

HDOJ 1194 Beat the Spread!的相关文章

(hdu 简单题 128道)hdu 1194 Beat the Spread!(已知两个数的和u两个数的差求这两个数)

题目: Beat the Spread! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5169    Accepted Submission(s): 2692 Problem Description Superbowl Sunday is nearly here. In order to pass the time waiting f

Hdu 1194 Beat the Spread!

Beat the Spread! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7001    Accepted Submission(s): 3700 Problem Description Superbowl Sunday is nearly here. In order to pass the time waiting for t

杭电 HDU 1194 Beat the Spread!

Beat the Spread! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5192    Accepted Submission(s): 2705 Problem Description Superbowl Sunday is nearly here. In order to pass the time waiting for

(HDU)1194 -- Beat the Spread!(球场赌徒)

题目链接:http://vjudge.net/problem/HDU-1194 给你两个非负整数的和以及差的绝对值,求出这个两个数,不存在输出impossible 坑爹的地方,如果两个数的和是一个奇数,整数解不存在. #include <iostream> #include <cstdio> using namespace std; int main() { int t,a,b,he,ca; scanf("%d",&t); while(t--) { sc

POJ 2301 Beat the Spread!

超水的一题,输入(x+y)和(x-y)  输出x,y,但是注意输出x,y都为非负整数(因为这个我还wa了两次..唉~~) Beat the Spread! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18154   Accepted: 8676 Description Superbowl Sunday is nearly here. In order to pass the time waiting for the h

Beat the Spread!

Beat the Spread! 垮掉的传播 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5329    Accepted Submission(s): 2782 Problem Description Superbowl Sunday is nearly here. In order to pass the time waitin

杭电ACM1194——Beat the Spread!

简单的数学题目,就是解方程. 不过需要注意的是,解出来的两个解没有负数. 输入m和n,方程1:x + y = m:方程2:| x - y | = n; x = (n + m)/ 2: y = (-n + m)/ 2: 注意:n + m和m - n 必须是偶数!~~做个判断就OK了. AC的代码: #include <iostream> using namespace std; int main() { int t, a, b; cin >> t; while(t--) { cin

HDU1194_Beat the Spread!

Beat the Spread! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4683    Accepted Submission(s): 2441 Problem Description Superbowl Sunday is nearly here. In order to pass the time waiting for

HDU——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201