USACO Section 1.1 (a simple simulation)

Your UFO in Your Ride Is Here He ...

The meaning of problems: given two length character string not exceeding 6 contains only uppercase letters, are determined two strings are equal to the product of mod47 (A is 1, B is a 2, ..., Z 26).

Directly in accordance with the meaning of problems to do on the line.

#include<bits/stdc++.h>
using namespace std;
char a1[10],b1[10];
int a[101],b[101];
int main(){
    gets(a1);gets(b1);
    int la=strlen(a1);
    int lb=strlen(b1);
    for(int i=0;i<la;i++)a[i+1]=a1[i]-64;
    for(int i=0;i<lb;i++)b[i+1]=b1[i]-64;
    int tota=1,totb=1;
    for(int i=1;i<=la;i++)tota*=a[i];
    for(int i=1;i<=lb;i++)totb*=b[i];
    if(tota%47==totb%47) cout<<"GO";
    else cout<<"STAY";
    return 0;
}

Greedy giver Greedy Gift Givers

Meaning of the questions: For a group of (NP a) send each other gifts to friends, GY make sure everyone send money to receive much more than that. In this problem, everyone got some money to give gifts, but the money will be divided equally among those who will receive his gift. However, in any group of friends, some people will send more gifts (probably because they have more of a friend), some people have prepared more money. Given a group of friends, no one name longer than 14 characters, each person will be given money to spend on gifts, and will receive his gift list of people, be sure to send more money than everyone received Number of.

Directly in accordance with the meaning of problems do the simulation, you can help map to make up numbers with the corresponding names.

//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
inline int read(){
    int x=0,o=1;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
    if(ch=='-')o=-1,ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int ans[20];
map<string,int>Map;
map<int,string>Mapp;
int main(){
    int n=read();
    for(int i=1;i<=n;++i){
        string s;cin>>s;
        Map[s]=i;Mapp[i]=s;
    }
    for(int i=1;i<=n;++i){
        string s;cin>>s;
        int sum=read(),num=read(),ave;
        if(!sum||!num)continue;
        ans[Map[s]]-=sum;
        if(sum%num)ave=floor(sum/num),ans[Map[s]]+=sum-num*ave;
        else ave=sum/num;
        for(int j=1;j<=num;++j){
            cin>>s;ans[Map[s]]+=ave;
        }
    }
    for(int i=1;i<=n;++i){
        cout<<Mapp[i]<<" "<<ans[i]<<endl;
    }
    return 0;
}

Black Friday Friday the Thirteenth

Meaning of the questions: No. 13 is a Friday. No. 13 on Friday less than on other days it? To answer this question, write a procedure that requires the calculation of the number of times the thirteenth month from Monday to Sunday falls. In a given cycle N, the required calculation January 1, 1900 to 1900 + N-1年 thirteenth Japan on December 31 falls on a Monday to Sunday, the number, N is a positive integer not more than 400. Here there is something you need to know: 1, January 1, 1900 and September Monday .2,4,6,11 other months have 30 days except February has 31 days leap year, February has 29 days, non-leap year February has 28 days .3, year divisible by 4 is a leap year (1992 = 4 * 498 so 1992 is a leap year, but 1990 is not a leap year) .4, the above rule is not suitable for century years. It can be divisible by 400 Century as a leap year, otherwise average. So, 1700,1800,1900 and 2100 is a leap year, but 2000 is a leap year.

Direct simulation meaning of the questions, pay attention to some details of the big Satsuki month February and leap year leap year on the line.

//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
inline int read(){
    int x=0,o=1;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
    if(ch=='-')o=-1,ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int ans[10];
inline int pd(int n){
    if(n%100!=0&&n%4==0)return 1;
    if(n%100==0&&n%400==0)return 1;
    return 0;
}
inline int PD(int n){
    if(n==0)return 2;
    if(n==2)return 0;
    if(n==4||n==6||n==9||n==11)return 1;
    return 2;
}
int main(){
    int n=read();
    int last=13%7;++ans[last];
    int year=1900,month=1,bj1=0,bj2=2;
    for(int i=2;i<=n*12;++i){
        ++month;
        if(month==13){
            month=1;++year;
            bj1=pd(year);
        }
        bj2=PD(month-1);
        if(bj2==0){
            if(bj1==0)++ans[last];  
            else{
                ++last;if(last==8)last=1;
                ++ans[last];
            }
        }
        if(bj2==1){
            last+=2;last=(last+7)%7;if(last==0)last=7;
            ++ans[last];
        }
        if(bj2==2){
            last+=3;last=(last+7)%7;if(last==0)last=7;
            ++ans[last];
        }
    }
    cout<<ans[6]<<" "<<ans[7]<<" ";
    for(int i=1;i<=5;++i)cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}

Broken necklace Broken Necklace

That Italy: one given by the r, b, three kinds of length w is n lowercase configured necklace, where OFF is obtained from the necklace and start collecting the same color beads from one end until you encounter a different color beads, at the other end doing the same thing (color may be different from the collection before this). it should break necklace determine where to collect the maximum number of beads. Note that both can be seen as w r, B can also be seen. The maximum number can be determined.

Analysis: First, the basic operation is broken ring so that the strand is a string times longer, and then small to large enumeration off position, but because we have to find this question to the two ends, so we have to three times longer than the original string, then start from the middle of the string, to determine whether each of the two longest length.

#include<bits/stdc++.h>
using namespace std;
string a;
int n,ans=-1;
int f(int x){
    int s=0;
    char a1=a[x];
    char b2=a[x+1];
    for(int i=x;;i--){
        if(a[i]==a1)s++;
        else if(a[i]=='w') s++;
        else break;
    }
    for(int i=x+1;;i++){
        if(a[i]==b2)s++;
        else if(a[i]=='w')s++;
        else break;
    }
    return s;
}
int main(){
    cin>>n;
    cin>>a;
    a=a+a+a;
    for(int i=n;i<2*n;i++){
        if(a[i]==a[i+1]) continue;
        if(a[i]=='w'){
            a[i]='r';
            ans=max(ans,f(i));
            a[i]='b';
            ans=max(ans,f(i));
            a[i]='w';
        }
        ans=max(ans,f(i));
    }
    ans=min(ans,n);
    if(ans==-1) ans=n;
    cout<<ans<<endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/PPXppx/p/11262664.html