跳到正文

个人记录

10.21提高组模拟赛

__DragonFly约 5 分钟
原文

这是 2025年10月24日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年10月24日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 5 分钟

版本

  1. v2当前
  2. v1

[https://share.note.youdao.com/s/ZfivG2hb] (icebin的tj)

01 串 (binary)

简单构造,思路详见icebin的tj和代码

正确代码

C++
#include <bits/stdc++.h>
using namespace std;

string mul(string s, int num) {
	string ans = "";
	for (int i = 1; i <= num; ++i) ans += s;
	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int T;
	cin >> T;
	while (T--) {
		int n, m;
		cin >> n >> m;
		string mx, mn;
		if (n <= 1 || (n % 2 == 1 && m <= 1)) {
			cout << "-1\n-1\n";
			continue;
		}
		if (n % 2 == 0) {
			mx = mul("1", n) + mul("0", m);
			mn = "1" + mul("0", m / 2 * 2) + "1" + mul("0", m % 2) + mul("1", n - 2);
		}
		else if (n % 2 != 0) {
			mx = mul("1", n - 2) + "0101" + mul("0", m - 2);
			mn = "1" + mul("0", m / 2 * 2 - 1) + "101" + mul("0", m % 2) + mul("1", n - 3);
		}
		else {
			cout << -1 << "\n" << -1 << "\n";
			continue;
		}
		cout << mx << "\n" << mn << "\n";
	}
	return 0;
}

树 (tree)

依题意得,树上距离计算:dist[u] + dist[v] - 2 × dist[lca(u,v)];步数计算:ceil(总距离 / c) = (距离 + c - 1) / c

正确代码

C++
#include <bits/stdc++.h>
using namespace std;
struct node {
	int v, w;
}; 
vector <node> v[10005];
int to[10005], nx[10005][30];
int wa[10005];
int n, m;

void dfs(int x, int fa) {
	to[x] = to[fa] + 1;
	nx[x][0] = fa;
	for (int i = 1; i < 30; ++i) {
		nx[x][i] = nx[nx[x][i - 1]][i - 1];
	}
	for (int i = 0; i < v[x].size(); ++i) {
		int xx = v[x][i].v, w = v[x][i].w;
		if (xx == fa) continue;
		wa[xx] = wa[x] + w;
		dfs(xx, x);
	}
	return ;
}

int up(int x, int y) {
	if (to[x] < to[y]) swap(x, y);
	int going = 29;
	while (to[x] > to[y] && going >= 0) {
		if (to[nx[x][going]] >= to[y]) {
			x = nx[x][going];
		}
		going--;
	}
	going = 29;
	while (x != y && going >= 0) {
		if (nx[x][going] != nx[y][going]) {
			x = nx[x][going], y = nx[y][going];
		}
		going--;
	}
	if (x != y) x = nx[x][0], y = nx[y][0];
	return x;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	freopen("tree.in", "r", stdin);
	freopen("tree.out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n - 1; ++i) {
		int x, y, z;
		cin >> x >> y >> z;
		v[x].push_back(node{y, z});
		v[y].push_back(node{x, z});
	}
	dfs(1, 0);
	cin >> m;
	for (int i = 1; i <= m; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		int going = up(a, b);
		int sum = wa[a] + wa[b] - wa[going] * 2;
		cout << ceil(sum * 1.0 / c) << "\n";
	}
	return 0;
}

T682365 括号序列(bracket)

详见icbin的tj