1. 程式人生 > 其它 >Educational Codeforces Round 102 (Rated for Div. 2)

Educational Codeforces Round 102 (Rated for Div. 2)

技術標籤:Codeforces

放假回家了,終於能開著燈打一場緊張刺激的cf了…
這一場四十幾分鍾過了三道題,第四題差一點。
有想一起打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;
}