首页 > 代码库 > Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

A
Neverending competitions

/*题意:给你n条路线,判断能否从起点出发,转回来。如果可以,“home”;否则,“contest” */ #include<cstdio>#include<cstring>#include<string>#include<map>using namespace std;const int N=1e5+5;int n,cnt,ans;char start[N],s1[N],s2[N];int main(){    scanf("%d",&n);    scanf("%s",start);    for(int i=1,l,len;i<=n;i++){        scanf("%s",s1);        len=strlen(s1);        for(int j=0;j<len;j++){            if(s1[j]==>){                l=0;                for(int k=j+1;k<len;k++){                    s2[l++]=s1[k];                }                s2[l]=\0;                s1[j-1]=\0;                break;            }        }        if(!strcmp(start,s1)) ans++;        if(!strcmp(start,s2)) ans--;    }    if(ans>0) puts("contest");    else puts("home");    return 0;}

 

B
Code obfuscation

/*题意:给你一个串,每改一个字符,判断其字符所有前驱是否也被修改 */#include<cstdio>#include<string>#include<iostream>using namespace std;bool mark[300];int main(){    string s;    cin>>s;    for(int i=0;s[i];i++){        mark[s[i]-a]=1;        for(int j=0;j<=(s[i]-a);j++){            if(!mark[j]){                puts("NO");                return 0;            }        }    }    puts("YES");    return 0;}

 

C
Table Tennis Game 2

/*题意:两人比赛乒乓球,打到k分完成一局问最多能完成多少局 */#include<cstdio>using namespace std;int main(){    int k,a,b;    scanf("%d%d%d",&k,&a,&b);    if((a<k&&b%k)||(b<k&&a%k)) puts("-1");    else printf("%d\n",a/k+b/k);    return 0;}

 

D
Artsem and Saunders

/*题意:(数学题)已知:f(x)->f(y) ,n 满足:g(h(x))=x{x∈[m]} ,h(g(x))=f(x){x∈[n]}. 求:m ,g(1..n),h(1..m) */#include<cstdio>using namespace std;inline int read(){    int x=0,f=1;char ch=getchar();    while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}    while(ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}    return x*f;}const int N=1e6+5;int n,m,f[N],g[N],h[N];int main(){    n=read();    for(int i=1;i<=n;i++) f[i]=read();    for(int i=1;i<=n;i++) if(f[i]!=i&&f[f[i]]!=f[i]){puts("-1");return 0;}    for(int i=1;i<=n;i++){        if(!g[f[i]]){            h[++m]=f[i];            g[f[i]]=m;        }        g[i]=g[f[i]];    }    printf("%d\n",m);    for(int i=1;i<=n;i++) printf("%d ",g[i]);putchar(\n);    for(int i=1;i<=m;i++) printf("%d ",h[i]);putchar(\n);    return 0;}

 

E
Tree Folding

F
Souvenirs

G
Math, math everywhere

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)