2019浙师大第十二届校赛(浙大命题)——第19场训练赛

 

 

问题 A: Little Sub and Applese 

时间限制: 1 Sec  内存限制: 256 MB
提交: 325  解决: 141
[提交] [状态] [命题人: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<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    while(getline(cin,s)){
        int len=s.length();
        s[len-1]='!';
        cout<<s<<endl;
    }
    return 0;
}

问题 B: Little Sub and Triples

时间限制: 1 Sec  内存限制: 256 MB
提交: 785  解决: 138
[提交] [状态] [命题人: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

找区间[l,r]是否存在a+b>c,因为查询次数较多,我们首先需要预处理下。打表发现如果数都是斐波那契数平铺在整数区间上这种极端情况不会有答案,打表发现这种情况支持大概46项,因为斐波那契数增长非常快。

打表代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxi=0x7fffffff;

int main(){
	ll a=1,b=1,tmp=a+b;
	ll cnt=2;
	while(tmp<=maxi){
		cnt++;
		a=b;
		b=tmp;
		tmp=a+b;
	}
	printf("%lld\n",cnt);  //46  超过46,就满足 
	return 0;
}

 

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
ll a[maxn],b[maxn];

int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	int l,r;
	while(q--){
		scanf("%d%d",&l,&r);
		if(r-l+1>46) printf("YES\n");
		else{
			bool flag=false;
			if(r-l+1>=3){
				for(int i=l;i<=r;i++){
					b[i-l]=a[i];
				}
				sort(b,b+r-l+1);
				for(int i=2;i<r-l+1;i++){
					if(b[i-2]+b[i-1]>b[i]){
						flag=true;
						break;
					}
				}
			} 
			if(flag) printf("YES\n");
			else printf("NO\n");
		}
		
	}
	return 0;
}

 

问题 D: Little Sub and Balloons

时间限制: 1 Sec  内存限制: 256 MB
提交: 158  解决: 136
[提交] [状态] [命题人: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<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n,a;
    scanf("%d",&n);
    set<int> s;
    while(n--){
        scanf("%d",&a);
        s.insert(a);
    }
    printf("%d\n",s.size());
    return 0;
}

问题 E: Little Sub and Traveling

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

题目描述

Little Sub lives in a country with n cities A[0..n-1]. He loves traveling very much.
It is Feb.14th, the Valentine Day. Little Sub decides to travel around the country with his girl friend.
Little Sub lives in A[0] and he wants to visit each city exactly once and go back to A[0] eventually.
However, Little Sub has made a rule for his journey: Suppose he is in city A[i], the next city he is about to visit must be either A[(i*2)%n] or A[(i*2 + 1)%n].
Please help him fi nd a possible route. If there are multiple answers, please give the one with the maximum alphabet order.
We say route A is larger than route B in the alphabet order when there exists i that A[i] > B[i]&A[1..i-1] = B[1..i-1] meets.

 

输入

The first line contains a positive integers n(2≤n≤10000).

 

输出

If there exists a legal route, please output n+1 integer separated by spaces in a single line, indicating the route.
If there is no possible route, please output  -1 instead.

 

样例输入

复制样例数据

4

样例输出

0 1 3 2 0

 

TLE

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e4+10;
int vis[maxn],a[maxn],n;

bool dfs(int id,int step){
	if(step==n){
		if((id*2)%n==0||(id*2+1)%n==0){
			a[step]=0;
			for(int i=0;i<n;i++){
				printf(" %d",a[i]);
			}
			printf("\n");
			return true;
		}else{
			return false;
		}
	}else{
		int mx=max((2*id)%n,(2*id+1)%n);
		int mn=min((2*id)%n,(2*id+1)%n);
		if(!vis[mx]){
			vis[mx]=1;
			a[step]=mx;
			if(dfs(mx,step+1)) return true;
			else if(!vis[mn]){
			    vis[mx]=0;
				vis[mn]=1;
				a[step]=mn;
				if(dfs(mn,step+1)) return true;
				else{
					vis[mn]=0;
					return false;	
				} 
			}else {
				vis[mx]=0;
				return false;	
			}
		}else if(!vis[mn]){
				vis[mn]=1;
				a[step]=mn;
				if(dfs(mn,step+1)) return true;
				else{
					vis[mn]=0;
					return false;	
				} 
		}else return false;
	}
}
 
int main(){
    scanf("%d",&n);
   // for(n=1;n<25;n++){
    	
	
    if(n%2==1) printf("-1\n");
    else{
        printf("0");
        vis[0]=1;
        memset(vis,0,sizeof(vis));
        a[0]=1;
        dfs(1,1);
    }
     
    //}
    return 0;
}

 


 

问题 I: Little Sub and Enigma

时间限制: 1 Sec  内存限制: 256 MB
提交: 887  解决: 96
[提交] [状态] [命题人: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<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s,t;
    cin>>s>>t;
    int len=s.length();
    map<char,char> mp;
    set<char> st,s1;
    bool flag=true;
    for(int i=0;i<len;i++){
        if(st.find(s[i])==st.end()){
            st.insert(s[i]);
            if(s1.find(t[i])==s1.end()){
                mp[s[i]]=t[i];
                s1.insert(t[i]);
            }else{
                flag=false;
            }
 
 
 
        }else{
            if(mp[s[i]]!=t[i]) flag=false;
        }
 
    }
 
    if(flag){
    	char a,b;
    	if(st.size()==25){
    		for(int i=0;i<26;i++){
    			if(st.find('a'+i)==st.end()){
    				a='a'+i;
    				break;
				}
			}
			for(int i=0;i<26;i++){
    			if(s1.find('a'+i)==s1.end()){
    				b='a'+i;
    				break;
				}
			}
			mp[a]=b;
		}
        map<char,char> ::iterator it;
        for(it=mp.begin();it!=mp.end();it++){
            printf("%c->%c\n",it->first,it->second);
        }
    }else{
        printf("Impossible\n");
    }
 
 
 
    return 0;
}

问题 J: Little Sub and Apples

时间限制: 1 Sec  内存限制: 256 MB
提交: 258  解决: 145
[提交] [状态] [命题人: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<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ll n,k,t,cnt;
	scanf("%lld%lld%lld",&n,&k,&t);
	cnt=n-k*t;
	if(cnt<0) cnt=0;
	printf("%lld\n",cnt);
	
	
	return 0;
}

问题 K: Little Sub and Triangles

时间限制: 2 Sec  内存限制: 256 MB
提交: 498  解决: 104
[提交] [状态] [命题人:admin]

题目描述

Little Sub loves triangles. Now he has a problem for you.
Given n points on the two-dimensional plane, you have to answer many queries. Each query require you to calculate the number of triangles which are formed by three points in the given points set and their area S should satisfy l≤S≤r.
Specially, to simplify the calculation, even if the formed triangle degenerate to a line or a point which S = 0, we still consider it as a legal triangle.

 

输入

The fi rst line contains two integer n, q(1≤n≤250, 1≤q≤100000), indicating the total number of points.
All points will be described in the following n lines by giving two integers x, y(-107≤x, y≤107) as their coordinates.
All queries will be described in the following q lines by giving two integers l, r(0≤l≤r≤1018).

 

输出

Output the answer in one line for each query.

 

样例输入

复制样例数据

4 2
0 1
100 100
0 0
1 0
0 50
0 2

样例输出

3
1

叉乘+二分。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=300;
const int N=2e7+10;
 
struct Node{
    ll x,y;
}mes[maxn];
ll v[N];
 
int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++){
        scanf("%lld%lld",&mes[i].x,&mes[i].y);
    }
    ll r=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                v[r++]=llabs(((mes[i].x-mes[k].x)*(mes[j].y-mes[i].y)-(mes[i].y-mes[k].y)*(mes[j].x-mes[i].x)));
            }
        }
    }
    sort(v,v+r);
    /*for(int i=0;i<r;i++){
        printf("%lld***\n",v[i]);
    }*/
    ll L,R;
    while(q--){
        scanf("%lld%lld",&L,&R);
        ll res=upper_bound(v,v+r,2*R)-lower_bound(v,v+r,2*L);
        printf("%lld\n",res);
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值