跳到正文

题解

题解:P1042 [NOIP 2003 普及组] 乒乓球

Ivan422约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
P1042

版本

  1. v1当前

基本语法题。

我们搞 44 个变量 m11m11 和 m21m21,y11y11,y21y21,分别表示我方 1111 分记分,我方 2121 分计分,对方 1111 分计分,对方 2121 分计分。

我们直接模拟。

注意,当两方得分 ∣m11−y11∣≤1|m11-y11|\leq 1,是不会被判胜负的,同理还有 ∣m21−y21∣≤1|m21-y21|\leq 1。

最后注意 E 是终止条件。

C++
#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int N=1e5+10;
string input;
string all;
struct ans21{int m,y;}a[N];
int m11,y11,m21,y21,cur21,len;
signed main(){
    while(cin>>input){all+=input;}
    len=all.size();
    for(int i=0;i<len;i++){
        if(all[i]=='W')m11++,m21++;
        if(all[i]=='L')y11++,y21++;
        if(all[i]=='E')break;
        if((m11>=11||y11>=11)&&abs(m11-y11)>1){
            cout<<m11<<":"<<y11<<endl;
            m11=0,y11=0;
        }
        if((m21>=21||y21>=21)&&abs(m21-y21)>1){
            a[++cur21]=ans21{m21,y21};
            m21=0,y21=0;
        }
    }
    a[++cur21]=ans21{m21,y21};
    cout<<m11<<":"<<y11<<endl<<endl;
    for(int i=1;i<=cur21;i++)cout<<a[i].m<<":"<<a[i].y<<endl;
    return 0;
}
原文