T1:Yay!

模拟

代码实现

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    string s;
    cin >> s;
    
    vector<int> cnt(256);
    for (char c : s) cnt[c]++;
    
    char one = '?';
    for (char c = 'a'; c <= 'z'; ++c) {
        if (cnt[c] == 1) one = c;
    }
    
    rep(i, s.size()) {
        if (s[i] == one) {
            cout << i+1 << '\n';
        }
    }
    
	return 0;
}

T2:Which is ahead?

模拟

代码实现

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    
    vector<int> x(n+1);
    rep(i, n) x[p[i]] = i;
    
    int q;
    cin >> q;
    rep(qi, q) {
        int a, b;
        cin >> a >> b;
        if (x[a] < x[b]) cout << a << '\n';
        else cout << b << '\n';
    }
    
	return 0;
}

T3:Many Replacement

只需记录每种字符最后变成了哪个字符即可

代码实现

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    
    string t;
    rep(i, 26) t += 'a'+i;
    
    rep(qi, q) {
        char c, d;
        cin >> c >> d;
        rep(i, 26) {
            if (t[i] == c) t[i] = d;
        }
    }
    
    rep(i, n) {
        int j = s[i]-'a';
        s[i] = t[j];
    }
    
    cout << s << '\n';
    
	return 0;
}

T4:Square Pair

可以先将每个数中的最大的平方因子除掉,然后就变成简单的组合计数问题了

代码实现

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    rep(i, n) {
        int x = a[i];
        for (int j = 2; ; ++j) {
            int y = j*j;
            if (y > x) break;
            while (x%y == 0) x /= y; 
        }
        a[i] = x;
    }
    
    ll ans = 0;
    int zero = 0;
    rep(i, n) {
        if (a[i] == 0) {
            zero++;
        }
    }
    ans += (ll)zero*(zero-1)/2;
    map<int, int> mp;
    for (int x : a) {
        if (x == 0) continue;
        ans += zero;
        ans += mp[x];
        mp[x]++;
    }
    
    cout << ans << '\n';
    
    return 0;
}