zoukankan      html  css  js  c++  java
  • 模拟与高精度 P1042 乒乓球

    题目

    https://www.luogu.com.cn/problem/P1042

    题目分析

    直到分差大于或者等于2,才一局结束:意思就是即使有人先得了1分,但是两人分差<2也不算结束,要继续比赛,直到分差大于或者等于2才这局结束

    代码

    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<cmath>
    #include<vector>
    using namespace std;
    typedef pair<int, int> p;
    vector<p>list;
    int main()
    {
        char tmp;
        int a=0, b=0;
        int a2 = 0, b2 = 0;
        int count1a = 0,count1b=0,count2a=0, count2b = 0;
        while (1)
        {
            scanf("%c", &tmp);
            if (tmp == 'E')
            {
                printf("%d:%d
    ", a, b);
                p temp = make_pair(a2, b2);
                list.push_back(temp);
                break;
            }
            if (tmp == 'W') { a++; a2++; count1a++; count2a++; }
            if (tmp == 'L') { b++; b2++; count1b++; count2b++; }
            if (abs(a - b) >= 2 && (count1a >= 11||count1b>=11))
            {
                printf("%d:%d
    ", a, b);
                a = 0; b = 0; count1a = 0; count1b = 0;
            }
            if (abs(a2 - b2) >= 2 && (count2a >= 21 || count2b >= 21))
            {
                p temp = make_pair(a2, b2);
                list.push_back(temp);
                a2 = 0; b2 = 0; count2a = 0; count2b = 0;
            }
    
    
        }
        printf("
    ");
        for (int i = 0; i < list.size();i++)
            printf("%d:%d
    ", list[i].first, list[i].second);
    }
  • 相关阅读:
    P2168 [NOI2015]荷马史诗
    P3195 [HNOI2008]玩具装箱TOY
    P1972 [SDOI2009]HH的项链
    P2339 提交作业usaco
    P3974 [TJOI2015]组合数学
    P2831 愤怒的小鸟
    [校内模拟题4]
    P3952 时间复杂度
    P3531 [POI2012]LIT-Letters
    2019.10.1 qbxt模拟题
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12832095.html
Copyright © 2011-2022 走看看