第十五届东北大学生编程大赛题解

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;
	}

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

算法编程张老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值