intmain() { int n, ans = 0; cin >> n >> s; //计算每种字母的数量 for(int i = 0; i < n; i ++) a[s[i] - 'A'] ++; //如果这种字母只剩,那么ans + 2, 否则 ans + 1 for(int i = 0; i < 26; i ++) while(a[i]) a[i] == 1 ? ans += 2 : ans ++, a[i] --; cout << ans << '\n';
#include<bits/stdc++.h> #define int long long usingnamespace std; structNode { int x, y, z; }; voidsolve() { int x, y; cin >> x >> y; int d = x * y / __gcd(x, y); if (x > y) swap(x, y); if (y % x == 0) { cout << 0 << "\n"; return; } vector<Node> g; int t = gcd(x, y); int p = d / t; g.push_back({1, x, y}); g.push_back({1, x, y}); //放入两个gcd int k = 0; int w = log2(p); while (w --) { g.push_back({2, t, t}); g.push_back({2, t, t}); t *= 2; } //这个也是每次放入两个gcd的二倍 w = log2(p); t = gcd(x, y); int ans = 0; for (int i = 0; i <= w; i ++) { if (p & 1) //类似二进制的拆分,直接一直放一直加即可 { if (!ans) ans = (1LL << i) * t; else { g.push_back({2, (1LL << i) * t, ans}); ans += (1LL << i) * t; } } p >>= 1; } cout << g.size() << "\n"; for (auto t : g) //输出 cout << t.x << ' ' << t.y << ' ' << t.z << '\n'; } signedmain() { int T; for (cin >> T; T -- ; ) solve(); }