2023 ICPC 网络赛 ADJL 现场 code | JorbanS

A

#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	vector<string> a, b, ans;
	map<string, bool> aa, bb, mp;
	for (int i = 0; i < n; i ++) {
		string ss; cin >> ss;
		if (aa[ss]) continue;
		aa[ss] = 1;
		a.push_back(ss);
	}
	for (int i = 0; i < m; i ++) {
		string ss; cin >> ss;
		if (bb[ss]) continue;
		bb[ss] = 1;
		b.push_back(ss);
	}
	int l = 0, r = 0;
	while (l < a.size() && r < b.size()) {
		if (!mp[a[l]]) {
			mp[a[l]] = 1;
			ans.push_back(a[l]);
		}
		if (!mp[b[r]]) {
			mp[b[r]] = 1;
			ans.push_back(b[r]);
		}
		l ++, r ++;
	}
	while (l < a.size()) {
		if (!mp[a[l]]) {
			mp[a[l]] = 1;
			ans.push_back(a[l]);
		}
		l ++;
	}
	while (r < b.size()) {
		if (!mp[b[r]]) {
			mp[b[r]] = 1;
			ans.push_back(b[r]);
		}
		r ++;
	}
	for (int i = 0; i < ans.size(); i ++) {
		cout << ans[i];
		if (i != ans.size() - 1) cout << endl;
	}
	return 0;
}

D

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

const int N = 1e6 + 2;
int f[N], w[N], v[N];
bool vis[N];

int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }

ll fx(ll x) { return x * (x - 1) / 2; }

int main() {
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i ++) f[i] = i, w[i] = 1;
	while (m --) {
		int a, b; cin >> a >> b;
		int pa = find(a), pb = find(b);
		if (pa == pb) {
			v[pa] ++;
			continue;
		}
		f[pa] = pb;
		w[pb] += w[pa];
		v[pb] += v[pa] + 1;
	}
	ll res = 0;
	vector<int> ans;
	int cnt1 = 0;
	bool ok = 0;
 	for (int i = 1; i <= n; i ++) {
		int x = find(i);
		if (vis[x]) continue;
		vis[x] = 1;
		ans.push_back(x);
		if (w[x] == 1) cnt1 ++;
		else if (v[x] != fx(w[x])) ok = 1;
	}
	for (auto i : ans) res += fx(w[i]) - v[i];
	if (!ok) {
	  	if (cnt1 >= 2) res ++;
	    else if (!cnt1) {
	    	int a = 1e6, b = 1e6;
	    	for (auto i : ans) {
	    		if (w[i] < a) {
	    			a = w[i];
	    			if (a < b) swap(a, b);
				}
			}
			res += fx(a + b) - fx(a) - fx(b);
		} else {
			ll add = 1e12;
			for (auto i : ans) if (w[i] != 1) add = min(add, fx(w[i] + 1) - v[i]);
			res += add;
		}
	}
	cout << res << endl;
	return 0;
}

J

#include <iostream>
#include <cmath>

using namespace std;

const double eps = 1e-8;

double dis2(double x1, double y1, double x2, double y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}

struct Point {
	double x, y, r;
	double x1, y1, x2, y2;
	Point(double x1, double y1, double x2, double y2) {
		x = (x1 + x2) / 2;
		y = (y1 + y2) / 2;
		r = dis2(x1, y1, x2, y2) / 2;
	}
	Point(int x, int y): x(x), y(y) {}
};

double ManDis(double x1, double y1, double x2, double y2) {
	return abs(x1 - x2) + abs(y1 - y2);
}

double findy(Point a, Point b, double x) {
	double dx = abs(x - b.x);
	double dy = sqrt(b.r * b.r - dx * dx);
	if (a.y < b.y) return b.y - dy;
	return b.y + dy;
}

double solve() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	Point a(x1, y1, x2, y2);
	cin >> x1 >> y1 >> x2 >> y2;
	Point b(x1, y1, x2, y2);
	double l, r;
	if (a.x < b.x) l = b.x - b.r, r = b.x;
	else l = b.x, r = b.x + b.r;
	while (abs(l - r) >= eps) {
		double L = (2 * l + r) / 3, R = (l + r * 2) / 3;
		if (ManDis(a.x, a.y, L, findy(a, b, L)) <= ManDis(a.x, a.y, R, findy(a, b, R))) r = R;
		else l = L;
	}
	return ManDis(a.x, a.y, l, findy(a, b, l));
}

int main() {
	int n; cin >> n;
	while (n --) printf("%.10lf\n", solve());
	return 0;
}

L

#include <iostream>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	int res = 2;
	while (n --) {
		int x; cin >> x;
		res = max(res, (x + m - 1) / m);
	}
	cout << res << endl;
	return 0;
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

JorbanS

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

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

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

打赏作者

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

抵扣说明:

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

余额充值