12.15 [diary] / [explanations] CodeForces # 607 (Div.2)

12.15

Today's game, VP readily come back a bit CF # 607 (Div2)

CF #607

  1. A: The suffix is ​​determined in three languages.

Large violence directly on the line, nothing to say.

#include<bits/stdc++.h>
using namespace std;
int main(){
    int T;
    scanf("%d",&T);
    for(int z=1;z<=T;++z){
        string s;
        cin>>s;
        int ed=s.size()-1;
        if (s[ed-1]=='p'&&s[ed]=='o')
            printf("FILIPINO\n");
        else if ((s[ed-3]=='d'&&s[ed-2]=='e'&&s[ed-1]=='s'&&s[ed]=='u')||(s[ed-3]=='m'&&s[ed-2]=='a'&&s[ed-1]=='s'&&s[ed]=='u'))
            printf("JAPANESE\n");
        else
            printf("KOREAN\n");
    }
    return 0;
}
  1. B: A string s, and two c, s exchange up to two characters, whether <c, the output <c string after the exchange asked.

Ideas: First, from the beginning to find s does not decrease the interval, until the lowered position. After finding a minimum backward last letter (and its location), and then start from scratch to find the first letter of the alphabet larger than the minimum, both of which can be exchanged.

Why not find someone drop zone? This ensures that the exchange may be better. At least we can put the two exchanged lowered position.

#include<bits/stdc++.h>
using namespace std;
int main(){
    int T;
    scanf("%d",&T);
    for(int z=1;z<=T;++z){
        string s1,s2;
        cin>>s1>>s2;
        int p=1;
        while(p<s1.size()&&s1[p-1]<=s1[p])
            ++p;
        if (p==s1.size()){
            if (s1<s2)
                cout<<s1<<endl;
            else
                cout<<"---"<<endl;
            continue;
        }
        int mnp=p;
        for(int i=p+1;i<s1.size();++i)
            if (s1[i]<=s1[mnp])
                mnp=i;
        int st=0;
        while(s1[st]<=s1[mnp])
            ++st;
        swap(s1[st],s1[mnp]);
        if (s1<s2)
            cout<<s1<<endl;
        else
            cout<<"---"<<endl;
    }
    return 0;
}
  1. C:https://codeforces.com/contest/1281/problem/C

Only the first bit x s notice is required. And after each round operation, s only later added (or without), it does not modify the existing section, so before len (s) <x, violence. After then do not update s, and only need to update the record s length.

This problem can not use string, constant too large T. We must turn into int array manually copied.

#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7,M=1e6+10;
char s[505];
int num[M];
int main(){
    int T;
    scanf("%d",&T);
    for(int z=1;z<=T;++z){
        int x;
        scanf("%d%s",&x,&s);
        int l=0,lenn=strlen(s),cnt=0,cl,cr;
        for(int i=0;i<lenn;++i)
            num[++cnt]=s[i]-'0';
        long long ans=lenn,lenc=0;
        while(ans<x){
            ++l,cl=l+1,cr=cnt,ans+=(num[l]-1)*(cnt-l);
            for(int i=1;i<=num[l]-1;++i){
                if (cnt>x)
                    break;
                for(int j=cl;j<=cr;++j){
                    if (cnt>x)
                        break;
                    num[++cnt]=num[j];
                }
            }
        }
        while(l<x)
            ++l,lenc=(ans-l+P)%P,ans=(ans+(num[l]-1)*lenc)%P;
        printf("%lld\n",ans);
    }
    return 0;
}

to sum up

A few days later to tidy up the template, do some data structure that, after planning what steps slowly to the future, in order to see what things are.

The end of this season, next season goodbye.

Guess you like

Origin www.cnblogs.com/diorvh/p/12046775.html