L1-019 谁先倒
Statement
Metadata
- 作者: 陈越
- 单位: 浙江大学
- 代码长度限制: 16 KB
- 时间限制: 400 ms
- 内存限制: 64 MB
划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就输了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。
下面给出甲、乙两人的酒量(最多能喝多少杯不倒)和划拳记录,请你判断两个人谁先倒。
输入格式
输入第一行先后给出甲、乙两人的酒量(不超过100的非负整数),以空格分隔。下一行给出一个正整数N(N行,每行给出一轮划拳的记录,格式为:
其中喊是喊出的数字,划是划出的数字,均为不超过100的正整数(两只手一起划)。
输出格式
在第一行中输出先倒下的那个人:A代表甲,B代表乙。第二行中输出没倒的那个人喝了多少杯。题目保证有一个人倒下。注意程序处理到有人倒下就终止,后面的数据不必处理。
输入样例
输出样例
Solution
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int main() {
    int arr[2] = {0};
    cin >> arr[0] >> arr[1];
    int q = arr[0], w = arr[1];
    int n;
    cin >> n;
    int a, b, c, d;
    int flag = 1;
    while (n--) {
        scanf("%d%d%d%d", &a, &b, &c, &d);
        if (flag) {
            if (a + c == b && a + c != d) {
                arr[0]--;
                if (arr[0] < 0)
                    flag = 0;
            }
            if (a + c == d && a + c != b) {
                arr[1]--;
                if (arr[1] < 0)
                    flag = 0;
            }
        } else
            continue;
    }
    if (arr[0] < 0)
        printf("A\n%d\n", w - arr[1]);
    else
        printf("B\n%d\n", q - arr[0]);
}
  Last update: May 4, 2022