Educational Codeforces Round 102 (Rated for Div. 2)

放假回家了,终于能开着灯打一场紧张刺激的cf了…
战况:在这里插入图片描述
在这里插入图片描述
rating+113,名字终于变色了。(我太菜了)
有想一起打CF的朋友可以加我qq:942845546,共同进步,共同上分,欢迎骚扰(传统艺能)。
比赛地址:Educational Codeforces Round 102 (Rated for Div. 2)
A - Replacing Elements
解题思路:读完题可以发现有两种情况是符合的,
1.所有的数字都小于等于d
2.最小的两个数相加小于等于d,就可以将所有大于d的数字替换
所以先排序,当最大的数小于等于d时(说明所有的数字都小于等于d)或最小的两个数相加小于等于d即为可行。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int t, n, d;
int a[110];
int main(){
    
    
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> t;
	while(t--){
    
    
		cin >> n >> d;
		for(int i = 1; i <= n; i++) cin >> a[i];
		sort(a + 1, a + 1 + n);
		if(a[n] <= d || a[1] + a[2] <=d) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

B - String LCM
解题思路:显然,在这一对字符串存在String LCM的情况下,String LCM的长度为这一对字符串的长度的最小公倍数。那么,我们就可以“合理”的使用字符串的特性——直接加减原字符串,当两个字符串加上原字符串加到长度为这一对字符串的长度的最小公倍数时,如果这两个处理后的字符串相等即为可以,输出其中一个(两个字符串一模一样),不相等就输出“-1”.

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int q;
int ls, lt, lc, cs;
string s, t, ss, tt;
int main(){
    
    
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> q;
	for(int i = 1; i <= q; i++){
    
    
		cin >> s >> t;
		ls = s.size();
		lt = t.size();
		lc = (ls * lt) / __gcd(ls, lt);
		ss = s;
		tt = t;
		for(int j = 1; j <= lc / ls - 1; j++){
    
    
			s += ss;
		}
		for(int j = 1; j <= lc / lt - 1; j++){
    
    
			t += tt;
		}
		if(s == t) cout << s << endl;
		else cout << "-1" << endl;
	}
	return 0;
}

C - No More Inversions
解题思路:我个人认为这道题的难点在于读题…所以我就不再此解释题意了(哈哈)
显然这是一道构造题,先输出1到2 * k - n然后输出 k到 2 * k - n(减)

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int t, k, n;

int main(){
    
    
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> t;
	while(t--){
    
    
		cin >> n >> k;
		for(int i = 1; i < 2 * k - n; i++){
    
    
			cout << i << ' ';
		}
		for(int i = k; i >= 2 * k - n; i--){
    
    
			cout << i << ' ';
		}
		cout << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42920035/article/details/112646367