SMU Summer 2023 Contest Round 13

发布时间 2023-08-18 02:01:44作者: Ke_scholar

SMU Summer 2023 Contest Round 13

A. Review Site

我们总是可以把差评放到另一个服务器,好评和中立放另一个,这样最多投票数就是好评与中立数

#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vector<int> r(n);
        int ans = 0;
        for (auto &i : r) {
            cin >> i;
            ans += (i != 2);
        }

        cout << ans << '\n';
    }

    return 0;
}

B. GCD Length

就是去凑\(a\)\(b\)都有\(c\)个相同因子就行,我这里凑得相同因子是\(11\),然后\(a\)一直乘\(2\)到对应位数,\(b\)一直乘\(3\)到对应位数

#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int, int> PII;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int a, b, c;
        cin >> a >> b >> c;
        int g = 0, cc = c;
        while (cc > 0) {
            g = g * 10 + 1;
            cc--;
        }

        if (a == b && a == c) {
            cout << g << ' ' << g << '\n';
        } else {
            int a1 = pow(10, a - 1), b1 = pow(10, b - 1), g1 = g, g2 = g;        
            while (g1 < a1) g1 *= 2;
            while (g2 < b1) g2 *= 3;
            cout << g1 << ' ' << g2 << '\n';
        }
    }

    return 0;
}

C. Yet Another Card Deck

因为\(a_i\)最多只有\(50\),所以我们可以用一个桶去记录每个数第一次的位置,然后将某个数提前的时候就将这个数前面位置的都往后挪一位

#include<bits/stdc++.h>

using i64 = long long;

using namespace std;

typedef pair<i64, i64> PII;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n,q;
	cin >> n >> q;
	vector<i64> a(n + 1);
	vector<int> t(55);
	for(int i = 1;i <= n;i ++){
		cin >> a[i];
		if(!t[a[i]]) t[a[i]] = i;
	}	
	while(q--){
		int x;
		cin >> x;
		cout << t[x] << ' ';
		for(int i = 1;i <= 50;i ++){
			if(i != x && t[i] < t[x])
				t[i]++;
		}	
		t[x] = 1;
	}

	return 0;
}

D. Min Cost String

观察第一个样例我们得出按照a ab ac ad b bc bd…这样去构造一个循环字符串即可满足要求

#include<bits/stdc++.h>

using i64 = long long;

using namespace std;

typedef pair<i64, i64> PII;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n,k;
    cin >> n >> k;
    string ans = "";

    for(int i = 'a';i < k + 'a';i ++){
        ans += i;
        for(int j = i + 1;j < k + 'a';j ++){
            ans += i, ans += j;
        }
    }

    for(int i = 0;i < n;i ++)
        cout << ans[i % ans.size()];
    cout << '\n';

    return 0;
}