40分,求调!

P1042 [NOIP2003 普及组] 乒乓球

wzxujiacheng__ @ 2024-10-07 20:36:56

#include<bits/stdc++.h>
using namespace std;
int f[2]={11,21},a[25*2500+10],n=0;
char tmp;
int read(){
    int ret=0,f=1;char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-')f=-f;ch=getchar();}
    while (isdigit(ch)) ret=(ret<<3)+(ret<<1)+(ch&15),ch=getchar();
    return ret*f;
}
int main(){
    while(1){
        scanf("%c",&tmp);
        if(tmp=='E')break;
        else if(tmp=='W')a[n++]=1;
        else if(tmp=='L')a[n++]=0;
    }
    for(int i=0;i<2;i++){
        int w=0,l=0;
        for(int j=0;j<n;j++){
            w+=a[j];l+=1-a[j];
            if((max(w,l)>=f[i])&&abs(w-1)>=2){
                printf("%d:%d\n",w,l);w=l=0;
            }
        }
        printf("%d:%d\n",w,l);
        printf("\n");
    }
    return 0;
}

by qiu_7 @ 2024-10-07 20:38:35

非常的简单啊好吧


by qiu_7 @ 2024-10-07 20:38:57

你在仔细看看就会发现


by ye_you @ 2024-10-07 20:43:03

abs(w-1)>=2........


by ye_you @ 2024-10-07 20:43:26

->abs(w-l)>=2


by ye_you @ 2024-10-07 20:44:52

#include<bits/stdc++.h>
using namespace std;
int f[2]={11,21},a[25*2500+10],n=0;
char tmp;
int read(){
    int ret=0,f=1;char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-')f=-f;ch=getchar();}
    while (isdigit(ch)) ret=(ret<<3)+(ret<<1)+(ch&15),ch=getchar();
    return ret*f;
}
int main(){
    while(1){
        scanf("%c",&tmp);
        if(tmp=='E')break;
        else if(tmp=='W')a[n++]=1;
        else if(tmp=='L')a[n++]=0;
    }
    for(int i=0;i<2;i++){
        int w=0,l=0;
        for(int j=0;j<n;j++){
            w+=a[j];l+=1-a[j];
            if((max(w,l)>=f[i])&&abs(w-l)>=2){//改成l
                printf("%d:%d\n",w,l);w=l=0;
            }
        }
        printf("%d:%d\n",w,l);
        printf("\n");
    }
    return 0;
}

by ye_you @ 2024-10-07 20:45:44

@wzxujiacheng__


by wzxujiacheng__ @ 2024-10-07 20:52:11

谢谢个位大佬


by wzxujiacheng__ @ 2024-10-07 20:54:50

@ye_you 但现在50分了


by craftmine @ 2024-10-11 11:08:13

@wzxujiacheng__ 你原来是abs(w-1)>=1,现在是abs(w-l)>=1,正解是abs(w-l)>=2,看清楚了


by craftmine @ 2024-10-11 11:09:16

你50分的记录:

if((max(w,l)>=f[i])&&abs(w-l)>=1){

  printf("%d:%d\n",w,l);w=l=0;
            }

| 下一页