组队赛(12周)

版权声明:转载时 别忘了注明出处 https://blog.csdn.net/ZCY19990813/article/details/84197432

比赛地址  http://acm.sdibt.edu.cn/vjudge/contest/view.action?cid=2117#overview

H

Sample Input
4
3 2
123456 6
999999 8
765432 7
Sample Output
2 5
6 5
8 5
7 5


题意:不懂。
思路:输出第二个数,和5
 

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#define MAX 1000000
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    scanf("%lld",&n);
    while(n--)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        printf("%lld 5\n",b);
    }
    return 0;
}


E

Sample Input
1 2 -1 4
2 4 8 -1
7 8 -1 21
5 -1 11 14
-1 2 4 6
-1 -1 -1 -1
Sample Output
3
16
-1
8
-1


题意:abcd4个数,可能是等差或等比序列,必须满足都大于等于一,小于等于1,000,000才可以,输出-1的位置的数,如果没有输出-1.
思路:一个个判断-1位置位置是哪,只可能是等差或等比序列。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
const int maxn = 26;
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c,d,m,n,flag=0;
    while(cin>>a>>b>>c>>d)
    {
        if(a==-1&&b==-1&&c==-1&&d==-1)
            break;
        if(a==-1)
        {
            if(d-c==c-b)
            {
                m=d-c;
                if(b-m<=0)
                    cout<<"-1"<<endl;
                else
                    cout<<b-m<<endl;
            }
            else
            if(d/c==c/b&&d%c==0&&c%b==0)
            {
                m=d/c;
                if(b/m>0&&b%m==0)
                    cout<<b/m<<endl;
                else
                    cout<<"-1"<<endl;
            }
            else
                cout<<"-1"<<endl;
        }
        if(b==-1)
        {
            m=d-c;
            n=d/c;
            if(2*m==c-a)
            {
                cout<<c-m<<endl;
            }
            else
            if(n*n==c/a&&c%a==0&&d%c==0)
            {
                m=c/n;
                if(c%n==0)
                    cout<<m<<endl;
                else
                    cout<<"-1"<<endl;
            }
            else
                cout<<"-1"<<endl;
        }
        if(c==-1)
        {
            m=b-a;
            n=b/a;
            if(2*m==d-b)
                cout<<d-m<<endl;
            else
            if(b%a==0&&b*n*n==d)
            {
                m=d/n;
                if(d%n==0)
                    cout<<m<<endl;
                else
                    cout<<"-1"<<endl;
            }
            else
                cout<<"-1"<<endl;
        }
        if(d==-1)
        {
            if(b-a==c-b)
            {
                m=b-a;
                if(m<=1000000)
                  cout<<m+c<<endl;
                else
                    cout<<"-1"<<endl;
            }
            else
            {
                if(b%a==0&&c%b==0&&b/a==c/b)
                {
                    n=b/a;
                    m=c*n;
                    if(m<=1000000)
                        cout<<m<<endl;
                    else
                        cout<<"-1"<<endl;
                }
                else
                    cout<<"-1"<<endl;
            }
        }
    }
    return 0;
}


F

INPUT
A .-
B -...
C -.-.
D -..
E .
F ..-.
G --.
H ....
I ..
J .---
K -.-
L .-..
M --
N -.
O ---
P .--.
Q --.-
R .-.
S ...
T -
U ..-
V ...-
W .--
X -..-
Y -.--
Z --..
7
PROGRAMMING
REGIONAL
PARIS
CONTEST
CENTRAL
SOUTH
ACM
6
.--.-.--
...---..--....
-.-..-.-.-..-.-..
.-..--...----..-.-..
.--..-.-----..-..-----..-.--.
-.-.----.-....-
4
.--.-.--
.-...---..-
.-...---..-.
.--.-.--
1
.--..-.-......
0
Sample Output
ACM SOUTH CENTRAL REGIONAL PROGRAMMING CONTEST
.-...---..- not in dictionary.
PARIS


题意:比对输出相对应的字符串,如果都存在输出,只要有一个不存在就输出第一个不存在的。
思路:两个map对应输出。
 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include <map>
#define eps 1e-8
#define memset(a,v) memset(a,v,sizeof(a))
using namespace std;
typedef long long ll;
map<ll,string> p;
map<string,string> q;
int main()
{
    ll i,n,j;
    char c;
    string s,ss,y,bb,cc;
    for(i=0; i<26; i++)
    {
        cin>>c>>s;
        p[c-'A']=s;
    }
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>ss;
        ll len=ss.size();
        map<ll,string>::iterator it;
        y.clear();
        for(j=0; j<len; j++)
        {
            for(it=p.begin(); it!=p.end(); it++)
            {
                if(it->first==ss[j]-'A')
                    y+=it->second;
            }
        }
        q[ss]=y;
    }
//    map<string,string>::iterator iter;
//    for(iter=q.begin(); iter!=q.end(); iter++)
//    {
//        cout<<iter->first<<" "<<iter->second<<endl;
//
//    }
    while(cin>>n)
     {
         if(n==0)
             break;
         bb.clear();
         cc.clear();
         map<string,string>::iterator iter;
         ll flag=0;
         ll flag1=0;
         for(i=0;i<n;i++)
         {
             s.clear();
             cin>>s;
             flag=0;

             for(iter=q.begin();iter!=q.end();iter++)
             {
                 //cout<<iter->first<<" "<<iter->second<<endl;
                 if(iter->second==s)
                 {
                     //cout<<iter->first<<endl;
                     bb+=iter->first;
                     if(i!=n-1)
                       bb+=' ';
                    flag=2;
                    break;
                 }
                /* else
                 {
                     cout<<s<<endl;
                     cout<<iter->first<<" "<<iter->second<<endl;
//                     flag=1;
//                     cc+=iter->second;
                     break;
                 }*/

             }
             //cout<<flag<<endl;
             if(flag!=2&&flag1==0)
             {
                 //cout<<s<<endl;
                 cc=s;
                 flag1=1;
             }
         }
            if(cc.size()!=0)
               cout<<cc<<" not in dictionary."<<endl;
           else
                cout<<bb<<endl;
     }
}

猜你喜欢

转载自blog.csdn.net/ZCY19990813/article/details/84197432
今日推荐