备战省赛组队训练赛第十九场 2019杭州师范大学校赛(浙江大学命题)

说明:三题签到。

问题 A: Little Sub and Applese

时间限制: 1 Sec  内存限制: 256 MB
提交: 323  解决: 139
[提交] [状态] [命题人:admin]

题目描述

’Why are you always repeating what I say?’ says Applese, a friend of Little Sub.
’Because it is the most important quality of mankind.’ says Little Sub.
Now it is your turn to repeat what Applese says.
Generally, each sentence Applese says will only contains ’A’..’Z’, ’a’..’z’, ’0’..’9’, space, ’!’ and ’.’.
Each sentence will defi nitely end with either ’!’ or ’.’. If it ends with ’.’, change it to ’!’ instead.
Applese has just passed his 17th birthday, we wish him and his friends very good luck in the future study and programming competitions.

 

输入

There are multiple cases, please read until the end of file.
Each case will only contain one sentence in one line, indicating what Applese says.
The total length of all sentences will not exceed 1000000.

 

输出

Output the answer in one line for each case.

 

样例输入

复制样例数据

Beautiful.
Excellent!

样例输出

Beautiful!
Excellent!
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    string a;
    while(getline(cin,a)){
        int index = a.size()-1;
        if(a[index]='.'||a[index]=='!')
            a[index]='!';
        cout<<a<<endl;
    }
 
    return 0;
}

问题 D: Little Sub and Balloons

时间限制: 1 Sec  内存限制: 256 MB
提交: 156  解决: 134
[提交] [状态] [命题人:admin]

题目描述

Little Sub is an ICPC participant.
Every time when Little Sub solves a new problem, a balloon will be given to him. Diff erent problems have distinct colors.
However, volunteers may give multiple balloons of the same kind to participants when they solve the problem.
Little Sub forgets how many problems he has solved in the last competition, but he still remember all balloons he received. Please help him calculate the number of passed problems.

 

输入

The fi rst line contains one positive integer n(1 ≤ n≤ 100), indicating the number of balloons.
The following line contains n integers, indicating all the balloons. To simplify the problem, we mark different colors as different ids.
All given integers will not exceed 231-1.

 

输出

Print one integer on the single line, indicating the answer.

 

样例输入

复制样例数据

4
1 1 1 10

样例输出

2

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
const int maxn = 105;
int main()
{
    int n,s;
    scanf("%d",&n);
    set<int> bal;
    for(int i = 0; i<n; i++)
    {
        scanf("%d",&s);
        bal.insert(s);
    }
    cout<<bal.size()<<endl;
 
    return 0;
}

 

问题 J: Little Sub and Apples

时间限制: 1 Sec  内存限制: 256 MB
提交: 221  解决: 130
[提交] [状态] [命题人:admin]

题目描述

Little Sub loves eating apples and he has n apples initially.
In the following t days, Little Sub will eat k apples each day. If the number of apple is less than k,he will eat all apples instead.
Please calculate the number of apples after t days.

 

输入

In the fisrt line, it contains three integer n, k, t(0≤n, k, t≤231-1).

 

输出

Output the answer in one line.

 

样例输入

复制样例数据

5 2 1

样例输出

3
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
const int maxn = 105;
int main()
{
    long long n,k,t;
    scanf("%d%d%d",&n,&k,&t);
    n=n-k*t;
    if(n<0)
        cout<<0<<endl;
    else
        cout<<n<<endl;
 
    return 0;
}
 

问题 B: Little Sub and Triples

时间限制: 1 Sec  内存限制: 256 MB
提交: 719  解决: 119
[提交] [状态] [命题人:admin]

题目描述

Little Sub has learned a new word ’Triple’, which usually means a group with three elements in it.
Now he comes up with an interesting problem for you.
Define 
Given an positive integer sequence A and some queries. In each query, you have to tell if there exists
a triple T = (x, y, z) such that:
1.x, y, z are unique integers.
2.l≤x, y, z≤r.
3.Ax≤Ay≤Az .
4.F(Ax, Ay, Az) > 1.

 

 

输入

The first line contains two positive integers n, q(1 ≤ n, q ≤ 200000).
The second line contains n positive integers, indicating the integer sequence.
The next q lines describe each query by giving two integer l, r(1≤l≤r≤n).
All given integers will not exceed 231-1.

 

输出

For each query, print YES if it exists any legal triple or NO otherwise.

 

样例输入

复制样例数据

4 2
1 2 3 4
1 3
2 4

样例输出

NO
YES
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 200000+5;
 
int n,q;
int a[maxn];
bool judge(int l,int r)
{
    vector<int> v;
    v.clear();
    for(int i = l; i<=r; i++)
    {
        v.push_back(a[i]);
        //cout<<a[i]<<endl;
    }
    int flag = 0;
    sort(v.begin(),v.end());
    for(int i = 2;i<v.size();i++){
        if(v[i]<v[i-1]+v[i-2]){
                flag = 1;
            break;
 
        }
    }
    if(flag == 1){
        return true;
    }
    else
        return false;
}
int main()
{
 
    scanf("%d%d",&n,&q);
    for(int  i = 1; i<=n; i++)
        scanf("%d",&a[i]);
    while(q--)
    {
        int l,r;
        scanf("%d %d",&l,&r);
        if(r-l>50){
            printf("YES\n");
            continue;
        }else{
            if(judge(l,r)==true)
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
}
//打表程序
//#include<iostream>
//#include<cstdio>
//#include<algorithm>
//#include<cstring>
//using namespace std;
//int main()
//{
//    int a[1005];
//    a[0]=1,a[1]=1;
//    for(int i = 2;i<=65;i++)
//    {
//        a[i]=a[i-1]+a[i-2];
//        printf("*%d %d %d %d\n",i,a[i],a[i-1],a[i-2]);
//    }
//    return 0;
//
//
//}

说明:按照斐波那契的增长速度,如果说超过了第47项,就超出斐波那契数的表示范围,所以设置一个上限,超过这个范围的答案都是可以满足两边之和大于第三边的;剩下的 暴力就可以了

问题 H: Little Sub and Counting

时间限制: 1 Sec  内存限制: 256 MB
提交: 405  解决: 126
[提交] [状态] [命题人:admin]

题目描述

Little Sub likes Math. Now he has a simple counting problem for you.
Given an positive integer sequence A, for each Ai , Please calculate how many elements Aj in the sequence satisfi ed AiAj > AjAi .

 

输入

The first line contains one positive integer n(1 ≤ n≤100000).
The following line contains n positive integers Ai(1≤Ai≤231-1).

 

输出

Please output n integer in one line and separate them by a single space. The ith integer indicates the answer concerning Ai .

 

样例输入

复制样例数据

3
1 2 5

样例输出

0 2 1

源程序:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn  = 100005;
int main()
{
    int n,a[maxn];
    scanf("%d",&n);
    vector<int> v2,v3,v4;
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
    }
    int v1 = 0;
    for(int i = 0 ; i<n; i++)
    {
        if(a[i]>4)
        {
            v2.push_back(a[i]);
        }
        else if(a[i]==2||a[i]==4)
        {
            v3.push_back(a[i]);
        }
        else if(a[i]==3)
        {
            v4.push_back(a[i]);
        }
        else
            v1++;
 
    }
    sort(v2.begin(),v2.end());
    for(int i = 0 ; i < n; i ++)
    {
 
        if(i!=0) printf(" ");
        if(a[i]>4)
        {
            printf("%d",v1+v2.size()-(upper_bound(v2.begin(),v2.end(),a[i])-v2.begin()));
            //printf("%d\n",upper_bound(v2.begin(),v2.end(),a[i])-v2.begin());
        }
        else if(a[i]==2||a[i]==4)
            printf("%d",v2.size()+v1);
        else if(a[i]==3)
            printf("%d",v1+v2.size()+v3.size());
        else
            printf("0");
    }
    return 0;
}

首先说一下,这个规律在比赛的时候确实没有找出来。

后来请教了一下别人才明白是什么意思:

如果是1的情况,那么任何一个数都无法满足,直接输出0

如果是2或者4的情况,可以把那个式子改变一下,很容易就能发现在构造的函数里面2和4的函数值是相等的,那么我要找符合条件的值,就需要去>=5的情况里面找

如果是3的情况,那么2和>=4的情况是满足的,(3^2>2^3)

如果是5及以上的情况,那么我们从5往右找满足的值就可以了。

这里5及以上的情况可以用upper_bound函数来查找,upper_bound是查找第一个大于某一个函数值的地址,然后再减去v.begin返回的就是这个数的下标

 

问题 I: Little Sub and Enigma

时间限制: 1 Sec  内存限制: 256 MB
提交: 968  解决: 120
[提交] [状态] [命题人:admin]

题目描述

Little Sub builds a naive Enigma machine of his own. It can only be used to encrypt/decrypt lower-case letters by giving each letter a unique corresponding lower-case letter. In order to ensure the accuracy, no contradiction or controversy is allowed in both the decryption and the encryption, which means all lower-case letters can only be decrypted/encrypted into a distinct lower-case letter.
Now we give you a string and its encrypted version. Please calculate all existing corresponding relationship which can be observed or deducted through the given information.

 

输入

The first line contains a string S, indicating the original message.
The second line contains a string T, indicating the encrypted version.
The length of S and T will be the same and not exceed 1000000.

 

输出

we use a string like ’x->y’ to indicate that letter x will be encrypted to letter y.
Please output all possible relationships in the given format in the alphabet order.
However, if there exists any contradiction in the given information, please just output Impossible in one line.

 

样例输入

复制样例数据

banana
cdfdfd

样例输出

a->d
b->c
n->f

解读:

一个初级译码器,给出一行明文,一行密文。

如果明文和密文有一对多的关系,错误

如果密文和明文有一对多的关系,错误

而且,如果前25组关系被确定了,那么第26组关系也被确定了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 305;
int main()
{
    string a,b;
    cin>>a;
    cin>>b;
    int vis1[maxn],vis2[maxn];
    memset(vis1,-1,sizeof(vis1));
    memset(vis2,-1,sizeof(vis2));
    int s = a.length();
    int flag = 0;
    int num = 0;
    for(int i = 0; i < s; i++)
    {
        if(vis1[a[i]-'a']==-1)//如果明文的某个字符没有被访问过
        {
            if(vis2[b[i]-'a']!=-1)//密文的某个字符已经被对应了
            {
                flag = 1;
                break;
            }//建立关系
                vis1[a[i]-'a'] = b[i]-'a';
                vis2[b[i]-'a'] = 1;
                num++;

        }
        else
        {//如果明文中某个字符已经被访问过了,后面又想给它建立新的关系,这种情况不存在
            if(vis1[a[i]-'a']!=b[i]-'a')
            {
                flag = 1;
                break;
            }

        }
    }
    if(flag == 1)
    {
        printf("Impossible\n");
        return 0;
    }
    //cout<<num<<endl;
    int flag2 = 0;
    if(num==25)
    {//第26组关系也确定
        for(int i = 0 ; i < 26 ; i++)
        {
            if(vis1[i]==-1)
            {
                //cout<<a[i]<<endl;
                for(int j = 0 ; j <26 ; j++)
                {
                    if(vis2[j]==-1)
                    {
                        vis1[i]= j;
                        flag2 = 1;
                        break;
                    }
                }

            }
            if(flag2 == 1)
                break;
        }

    }
    for(int i = 0 ; i < 26 ; i++)
    {
        if(vis1[i] != -1)
        {
            printf("%c->%c\n",i+'a',vis1[i]+'a');
        }

    }
}

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值