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

來源:互聯網
上載者:User

標籤:end   比賽   否則   pac   color   起點   font   main   map   

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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.