Codeforces Round #786 (Div. 3) ABCD

目录

A. Number Transformation

B. Dictionary

C. Infinite Replacement

D. A-B-C Sort


A. Number Transformation

题目链接:Problem - A - Codeforces

题面:

 

题意:t组样例,每组一个x,y,可以选择一个a使x变成a * x,问需要几步使x 变成b,如果不行输出0 0

思路:如果y可以除尽x,那么就是1 y / x,否则就是 0 0

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while(t--){
        int x, y;
        cin >> x >> y;
        if(y % x == 0){
            cout << "1 " << y / x << endl;
        }else{
            cout << "0 0" << endl;
        }
    }
    return 0;
}

B. Dictionary

题目链接:Problem - B - Codeforces

题面:

 

题意:有一种奇怪的语言:只有两个英文小写字母组成,两个字母不能相同。

第一个使ab;

第二个使ac;

最后一个使zy;

现在给定一个字符串,问是第几个

思路: 每个不同字母开头都有25个,然后遍历一遍后面的即可确定

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin >> t;
	while(t--){
		string s;
		cin >> s;
		int ans = 1;
		ans += (s[0] - 'a') * 25;
		char c = 'a';
		for(int j = 0; j < 26; j++){
			if(c == s[0]){
				c++;
				continue;
			}
			if(c == s[1]){
				break;
			}
			ans++;
			c++;
			
		}
		cout << ans << endl;
	}
	return 0;
}

C. Infinite Replacement

题目链接:Problem - C - Codeforces

题面:

题意: 给定一串只有‘a'的字符串s和t,每次可以选择一个'a',变成t,问一共由多少种不同的字符串,如果无限打就输出-1

思路:如果t是”a“,那么无论怎么变都是1种,如果t串包含'a'那么就能一直增加下去,就是-1,否则就是2^s的长度次

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
ll power(ll a, ll n){
	if(n == 0){
		return 1;
	}
	ll tmp = 1;
	while(n){
		if(n & 1){
			tmp *= a;
		}
		a *= a;
		n /= 2;
	}
	return tmp;
}
int main(){
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--){
		string a, b;
		cin >> a >> b;
		if(b == "a"){
			cout << 1 << endl;
		}else{
			bool f = 0;
			for(int j = 0; j < b.length(); j++){
				if(b[j] == 'a'){
					f = 1;
				}
			}
			if(f == 1){
				cout << -1 << endl;
			}else{
				cout << power(2, a.length()) << endl;
			}
		}
	}
	return 0;
}

D. A-B-C Sort

题目链接:Problem - D - Codeforces

题面:

 

题意:有a,b,c,三个数组,刚开始就a有n个数,b,c为空 ,有两步操作

1:如果a不为空,取a的最后一个放在b的中间,如果b的数量为奇数,可以决定放左边或者右边

2:如果b不为空,取b的中间放在c的最后,如果b为偶数,可以选择左边那个还是右边那个

1全部完成后才能进行2,如果c是可以一个非递减数列就输出YES,否则NO

思路:如果一个数字是奇数次去b数组的,那么他的值一定小于上一个去b的,如果是偶数次的,就可以和前面进b的调换位置,但是一定要小于前面第二个去b的

#include<bits/stdc++.h>
using namespace std;
int arr[200005];
int main(){
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		for(int i = 0; i < n; i++){
			cin >> arr[i];
		
		}
		bool f = 0;
		int a = 1000005;//存上一个去b的
		int b = 1000005;//存前一个去b的
		for(int i = 1; i <= n; i++){
			if(i & 1){
				if(arr[n - i] > a){
					f = 1;
					break;
				}else{
					b = a;
					a = arr[n - i];
				}
			}else{
				if(arr[n - i] > b){
					f = 1;
					break;
				}else{
					b = a;
					a = min(a, arr[n - i]);
				}
			}
		}
		if(f){
			cout << "NO" << endl;
		}else{
			cout << "YES" << endl;
		}
	}
	return 0;
}

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值