E.
题意就是完美数是这个数的因子和等于他,半完美数是只要有一部分因子就行,给一个数,求构成半完美的因子。
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long p;
cin >> p;
cout << 6* p << " " << 3 << endl;
cout << p << " " << 2 * p << ' ' << 3* p << endl;
}
}
I.
就是判断区间点菜价格取值就行。
K.
我们给查询攻击和桥的坚固性排成大到小,然后按照并查集来安装,1*2*3方式统计桥的个数。
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y;
long long k;
} a[10000007];
long long fa[1000007], num[100007], ans[1000007];
struct node1 {
long long x;
int id;
} p[1000007];
bool cmp(node a1, node b1) {
return a1.k > b1.k;
}
bool cmp1(node1 a1, node1 b1) {
return a1.x > b1.x;
}
long long father(int x) {
if (fa[x] == x)
return x;
return fa[x] = father(fa[x]);
}
int main() {
cin.sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
fa[i] = i;
num[i] = 1;
}
for (int i = 1; i <= m; i++) {
cin >> a[i].x >> a[i].y >> a[i].k;
}
for (int i = 1; i <= q; i++) {
cin >> p[i].x;
p[i].id = i;
}
sort(a + 1, a + 1 + m, cmp);
sort(p + 1, p + 1 + q, cmp1);
int j = 1;
long long sum = 0;
for (int i = 1; i <= q; i++) {
long long t = p[i].x;
while (j <= m && a[j].k >= t) {
long long xx = father(a[j].x), yy = father(a[j].y);
if (xx != yy) {
sum += num[xx] * num[yy];
num[yy] += num[xx];
fa[xx] = yy;
}
j++;
}
ans[i] = sum;
}
for (int i = 1; i <= q; i++) {
cout << ans[i] << endl;
}
}
}
M.
纯模拟,用stringstream来取单词就行。
#include <bits/stdc++.h>
using namespace std;
map<string, string>mp;
int main() {
mp["iu"] = "q", mp["en"] = "f", mp["ei"] = "w", mp["eng"] = "g";
mp["ang"] = "h", mp["uan"] = "r", mp["an"] = "j", mp["ue"] = "t";
mp["uai"] = "k", mp["ing"] = "k", mp["un"] = "y", mp["uang"] = "l";
mp["iang"] = "l", mp["sh"] = "u", mp["ou"] = "z", mp["ch"] = "i";
mp["ia"] = "x", mp["ua"] = "x", mp["uo"] = "o", mp["ao"] = "c";
mp["ie"] = "p", mp["zh"] = "v", mp["ui"] = "v", mp["in"] = "b";
mp["ong"] = "s", mp["iong"] = "s", mp["iao"] = "n", mp["ai"] = "d";
mp["ian"] = "m";
string s;
string t;
while (getline(cin, s)) {
string str = "";
stringstream ss(s);
int x1 = 0;
while (ss >> t) {
if (x1)
str += " ";
else
x1 = 1;
int len = t.size();
if (len == 1)
str += t + t;
else if (len == 2)
str += t;
else {
if (t[0] == 'z' || t[0] == 's' || t[0] == 'c') {
if (t[1] == 'h') {
string a = "";
for (int i = 0; i <= 1; i++) {
a += t[i];
}
str += mp[a];
if (len == 3)
str += t[2];
else {
string a = "";
for (int i = 2; i < len; i++) {
a += t[i];
}
str += mp[a];
}
} else {
string a = "";
str += t[0];
for (int i = 1; i < len; i++) {
a += t[i];
}
str += mp[a];
}
} else {
string a = "";
str += t[0];
for (int i = 1; i < len; i++) {
a += t[i];
}
if (!mp.count(a))
str += mp[t];
else {
str += mp[a];
}
}
}
}
cout << str << endl;
}
}