Codeforces Beta Round #73 (Div. 2 Only)——A,B,C

A. Chord
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya studies music.

He has learned lots of interesting stuff. For example, he knows that there are 12 notes: CC#DD#EFF#GG#ABH. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones

Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.

Let's define a major triad. Let the triad consist of notes XY and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between Xand Z, accordingly, equals 7 semitones.

A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.

For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.

Help Vasya classify the triad the teacher has given to him.

Input

The only line contains 3 space-separated notes in the above-given notation.

Output

Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <map>
using namespace std;
const int maxn=1000+5;
map<string,int>m;
int judge(string a,string b,string c)
{
    int x=(m[b]-m[a]+12)%12;
    int y=(m[c]-m[b]+12)%12;
    int z=(m[c]-m[a]+12)%12;
   // cout<<x<<y<<z<<endl;;
    if(x==4&&y==3&&z==7) return 1;
    if(x==3&&y==4) return 0;
    return -1;
}
int main()
{
    m["C"]=1;
    m["C#"]=2;
    m["D"]=3;
    m["D#"]=4;
    m["E"]=5;
    m["F"]=6;
    m["F#"]=7;
    m["G"]=8;
    m["G#"]=9;
    m["A"]=10;
    m["B"]=11;
    m["H"]=12;
    string a,b,c;
    cin>>a>>b>>c;
    if(judge(a,b,c)==1||judge(a,c,b)==1||judge(b,a,c)==1||judge(b,c,a)==1||judge(c,a,b)==1||judge(c,b,a)==1)
         cout<<"major";
    else if(judge(a,b,c)==0||judge(a,c,b)==0||judge(b,a,c)==0||judge(b,c,a)==0||judge(c,a,b)==0||judge(c,b,a)==0)
         cout<<"minor";
    else cout<<"strange";
    return 0;
}

B. Keyboard
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has n rows of keys containing m keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they make lowercase letters uppercase.

Vasya can press one or two keys with one hand. However, he can only press two keys if the Euclidean distance between the centers of the keys does not exceed x. The keys are considered as squares with a side equal to 1. There are no empty spaces between neighbouring keys.

Vasya is a very lazy boy, that's why he tries to type with one hand as he eats chips with his other one. However, it is possible that some symbol can't be typed with one hand only, because the distance between it and the closest "Shift" key is strictly larger than x. In this case he will have to use his other hand. Having typed the symbol, Vasya returns other hand back to the chips.

You are given Vasya's keyboard and the text. Count the minimum number of times Vasya will have to use the other hand.

Input

The first line contains three integers nmx (1 ≤ n, m ≤ 30, 1 ≤ x ≤ 50).

Next n lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly m keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys are marked with the "S" symbol.

Then follow the length of the text q (1 ≤ q ≤ 5·105). The last line contains the text T, which consists of q symbols, which are uppercase and lowercase Latin letters.

Output

If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes).

#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=30+5;
bool can[maxn],canb[maxn];//can为1表示小写出现,大写为1表示不需要两只手
char in[maxn][maxn];
char tmp[500005];
int main()
{
    int n,m,x;
    scanf("%d%d%d",&n,&m,&x);
    for(int i=0;i<n;i++) scanf("%s",in[i]);
    bool has=false;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            if(in[i][j]=='S')
            {
                has=true;
                for(int k=0;k<n;k++)
                    for(int l=0;l<m;l++)
                        if((k-i)*(k-i)+(l-j)*(l-j)<=x*x&&in[k][l]!='S')
                            canb[in[k][l]-'a']=1;
            }
            else can[in[i][j]-'a']=1;
    int q,i,ans=0;
    scanf("%d%s",&q,tmp);
    for(i=0;i<q;i++)
        if(tmp[i]>='A'&&tmp[i]<='Z')
        {
            if(!has) break;
            if(canb[tmp[i]-'A']){}
            else if(can[tmp[i]-'A']) ans++;
            else break;
        }
        else if(can[tmp[i]-'a']) {}
        else break;
    if(i<q) printf("-1\n");
    else printf("%d\n",ans);
    return 0;
}
C. Trains
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.

When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).

We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.

Help Vasya count to which girlfriend he will go more often.

Input

The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).

Output

Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.

数论题,只会暴力模拟。

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
__int64 gcd(__int64 a,__int64 b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    __int64 a,b;
    cin>>a>>b;
    __int64 lcm=a>b?a/gcd(a,b)*b:a/gcd(b,a)*b;
    __int64 t=0,sum=0,sud=0,n1=1,n2=1,Min=0;
    while(1)
    {
        t=min(n1*a,n2*b);
        if(t==n1*a) n1++;if(t==n2*b) n2++;
        if(t==lcm){
            if(sum>sud) sud+=lcm-Min;
            else sum+=lcm-Min;
            break;
        }
        if(t%a==0) sum+=t-Min;
        if(t%b==0) sud+=t-Min;
        Min=t;
    }
    if(sum==sud) cout<<"Equal";
    else if(sum>sud) cout<<"Dasha";
    else cout<<"Masha";
    return 0;
}


你可能感兴趣的:(Codeforces Beta Round #73 (Div. 2 Only)——A,B,C)