zoukankan      html  css  js  c++  java
  • 【题解】NOIP2003 乒乓球

    这道题我交了好几次,果然还是太菜了(

    说一下注意的点吧:

    • 要特判一下只有E的情况,应该输出0:0
    • 这里的11分制是指其中一个人有11分而不是总共11分
    • 要注意刚好比完一场还需要进行下一场,如果下一场没有数据应该输出0:0

    具体请看代码

    /* P1217 乒乓球
     * 作者: RainbowBird
     * 日期: 2020-08-18
     * 算法: 模拟
     */
    
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    using namespace std;
    
    int n, game[25 * 2500 + 5];
    
    int main() {
        // 读入数据
        memset(game, 0, sizeof(game));
        char ch = getchar();
        while (ch != 'E') {
            if (ch == 'W') game[++n] = 1;
            else if (ch == 'L') game[++n] = 2;
            ch = getchar();
        }
    
        if (n == 0) n = 1;
    
        // 11分制
        {
            int k = 1;
            while (k <= n + 1) {
                // 进行一轮比赛
                int a = 0, b = 0, i = 1;
                while (k <= n + 1) {
                    if ((a >= 11 || b >= 11) && abs(a-b) >= 2) break;
    
                    if (game[k] == 1) a++;
                    else if (game[k] == 2) b++;
    
                    k++, i++;
                }
    
                // 结束这一轮比赛
                printf("%d:%d
    ", a, b);
            }
        }
    
        printf("
    ");
    
        // 21分制
        {
            int k = 1;
            while (k <= n + 1) {
                // 进行一轮比赛
                int a = 0, b = 0, i = 1;
                while (k <= n + 1) {
                    if ((a >= 21 || b >= 21) && abs(a-b) >= 2) break;
    
                    if (game[k] == 1) a++;
                    else if (game[k] == 2) b++;
    
                    k++, i++;
                }
    
                // 结束这一轮比赛
                printf("%d:%d
    ", a, b);
            }
        }
    
        return 0;
    }
    
    
  • 相关阅读:
    vs2013+opencv2410的一些问题
    windows下bat批量处理启动exe
    https://blog.csdn.net/u012235003/article/details/54576737
    error LNK2005:"private:__thiscall编译错误
    后缀自动机学习笔记
    后缀数组学习笔记
    AC自动机学习笔记
    KMP
    Manacher学习笔记
    字符串Hash/树Hash学习笔记
  • 原文地址:https://www.cnblogs.com/luoling8192/p/13523682.html
Copyright © 2011-2022 走看看