Educational Codeforces Round 102 (Rated for Div. 2)

Going home from the holiday, I can finally play an exciting CF with the lights on... The
situation: Insert picture description here
Insert picture description here
rating +113, the name finally changed color. (I'm too good)
Friends who want to play CF together can add me qq: 942845546, make progress together, score together, and welcome harassment (traditional arts).
Competition address: Educational Codeforces Round 102 (Rated for Div. 2)
A-Replacing Elements
problem-solving idea: After reading the problem, you can find that there are two situations that are consistent.
1. All numbers are less than or equal to d
2. The smallest two If the sum of the numbers is less than or equal to d, you can replace all the numbers greater than d
so you can sort first. When the largest number is less than or equal to d (indicating that all numbers are less than or equal to d) or the smallest two numbers are less than or equal to d As feasible.

#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
Problem Solving Idea: Obviously, in the case of String LCM in this pair of strings, the length of String LCM is the least common multiple of the length of this pair of strings. Then, we can "reasonably" use the characteristics of the string-directly add and subtract the original string, when the length of the two strings plus the original string is the least common multiple of the length of the pair of strings, if this If the two processed strings are equal, you can output one of them (the two strings are exactly the same), and output "-1" if they are not equal.

#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
problem-solving idea: I personally think that the difficulty of this problem lies in reading the problem... so I will not explain the meaning of the problem here (haha)
Obviously this is a construction problem, first output 1 to 2 * k-n Then output k to 2 * k-n (minus)

#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;
}

Guess you like

Origin blog.csdn.net/qq_42920035/article/details/112646367