和测试点答案一样然后爆0...

P2697 宝石串

Kiritan @ 2019-12-06 14:14:59

#include<cstdio>
#define max(a,b) a>b?a:b
#define swap(a,b) int k;k=a;a=b;b=k
char c;
long long f[1000005],n(1),maxn,a,b;
int main(){
    while(~scanf("%c",&c)){
        if(c=='G'){b=a+1;n++;}
        if(c=='R'){b=a-1;n++;}
        if(f[b]==0&&b!=0)f[b]=n;
        maxn=max(maxn,n-f[b]);
        swap(a,b);
    }
    printf("%lld",maxn-1);
    return 0;
}

by nkinclude @ 2019-12-06 14:17:11

爆0是得0分的意思


by Kiritan @ 2019-12-06 14:20:17

@nkinclude 70分在练习中不等于0吗...


by nkinclude @ 2019-12-06 14:21:05

@Kiritan 70不等于0


by nkinclude @ 2019-12-06 14:22:16

70!=0不是常识吗。。。

您想太简单了。


by Kiritan @ 2019-12-06 14:22:57

好吧,重点不是这个...,问题是怎么搞...


by deaf @ 2019-12-06 14:43:13

@nkinclude 你怎么想的啊没A就是没A怎么说话的啊


by nkinclude @ 2019-12-06 14:43:44

@qurui PA


by hjxhjx @ 2019-12-06 14:58:34

Orz不用std的大佬


by Kiritan @ 2019-12-06 15:01:32

解决了...被迫求字符串长度... :(


by Kiritan @ 2019-12-06 15:03:07

#include<cstdio>
#include<cstring>
#define max(a,b) a>b?a:b
#define swap(a,b) int k;k=a;a=b;b=k
char c[1000005];
long long f[1000005],n(1),maxn,a,b,l;
int main(){
    scanf("%s",&c);
    l=strlen(c);
    for(int i(0);i<l;i++){
        if(c[i]=='G')b=a+1;
        if(c[i]=='R')b=a-1;
        if(f[b]==0&&b!=0)f[b]=i+1;
        maxn=max(maxn,i+1-f[b]);
        swap(a,b);
    }
    printf("%lld",maxn);
    return 0;
}

|