Chapter1 入門/Section 1.2

王瀚同學發表於2019-04-13

牛客能把USACO的training都弄下來很資瓷啊 1.2全是入門題吧,我貼下程式碼就好了吧

A.你要乘坐的飛碟在這裡

#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL mod=47;
string S,P;
int main()
{
    cin>>S>>P;
    LL sum1=1;
    for(int i=0;i<S.length();i++){
        LL res=S[i]-'A'+1;
        sum1*=res;
        sum1%=mod;
    }
    LL sum2=1;
    for(int i=0;i<P.length();i++){
        LL tmp=P[i]-'A'+1;
        sum2*=tmp;
        sum2%=mod;
    }
    if(sum1==sum2){
        printf("GO\n");
    }else{
        printf("STAY\n");
    }
    return 0;
}
複製程式碼

B.貪婪的禮物送禮者

#include "bits/stdc++.h"
using namespace std;
const int maxn=100+10;
string s[maxn];
int n;
string name;
map<string,int>mp;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) cin>>s[i];
    while(cin>>name){
        int x,num;
        scanf("%d%d",&x,&num);
        if(num==0) continue;
        int div=x/num;
        string res="";
        mp[name]-=x/num*num;
        for(int i=1;i<=num;i++){
            cin>>res;
            mp[res]+=div;
            res="";
        }
        name="";
    }
    for(int i=1;i<=n;i++){
        cout<<s[i]<<" "<<mp[s[i]]<<endl;
    }
    return 0;
}
複製程式碼

C.黑色星期五

#include "bits/stdc++.h"
using namespace std;
int n;
int m1[]={31,31,28,31,30,31,30,31,31,30,31,30};
int m2[]={31,31,29,31,30,31,30,31,31,30,31,30};
bool judge(int year){
    if(year%100==0){
        if(year%400==0) return true;
        return false;
    }else{
        if(year%4==0) return true;
        return false;
    }
}
int vis[20];
int main()
{
    scanf("%d",&n);
    n=n+1900-1;;
    int sum=3;
    for(int year=1900;year<=n;year++){
        if(judge(year)){
            for(int j=0;j<12;j++){
                sum+=m2[j];
                sum%=7;
                vis[sum]++;
            }
        }else{
            for(int j=0;j<12;j++){
                sum+=m1[j];
                sum%=7;
                vis[sum]++;
            }
        }
    }
    printf("%d %d ",vis[6],vis[0]);
    for(int i=1;i<=5;i++) printf("%d ",vis[i]);
    printf("\n");
    return 0;
}
複製程式碼

D.破碎的項鍊

#include "bits/stdc++.h"
using namespace std;
int n;
string s;
int solve(int x){
    char ch1=s[x];
    char ch2=s[x+1];
    int cnt=0;
    for(int i=x;;i--){
        if(ch1==s[i]||s[i]=='w') cnt++;
        else break;
    }
    for(int i=x+1;;i++){
        if(ch2==s[i]||s[i]=='w') cnt++;
        else break;
    }
    return cnt;
}
int main()
{
    scanf("%d",&n);
    cin>>s;
    s=s+s+s;
    int mx=0;
    for(int i=n;i<2*n;i++){
        if(s[i]=='w'){
            s[i]='r';
            mx=max(mx,solve(i));
            s[i]='b';
            mx=max(mx,solve(i));
            s[i]='w';
        }
        mx=max(mx,solve(i));
    }
    printf("%d\n",min(mx,n));
    return 0;
}
複製程式碼

相關文章