跳到正文

个人记录

250726总结

wendywu约 18 分钟
原文
文章信息与版本

文章信息

发布
2025年7月26日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 18 分钟

版本

  1. v1当前

day5:构造
差一个题(差点写完叻)

A - Divide coins

写了30分钟,一遍过:)
放k个1,剩下的都是4就行叻:)

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int n, k;

int main () {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		if (i <= k) {
			cout << 1;
		} else {
			cout << 4;
		}
	}
	return 0;
}

B - 这个题简单,先做这个!

写了19分钟,WA一发:)
WA一发是因为看错题叻qwq
还真是这个题简单,先做这个
因为众所周知, 相邻的2个数互质,所以尽量让aia_i比ai+1a_{i + 1}小2就是最小的。那就先一段偶数再一段奇数,中间断开的那里用1就好了:)

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int t, n;

int main () {
	for (cin >> t; t--;) {
		cin >> n;
		for (int i = 2; i <= n; i += 2) {
			cout << i << ' ' ;
		}
		for (int i = 1; i <= n; i += 2) {
			cout << i << " ";
		}
		cout << "\n";
	}
	return 0;
}

C - Recover Statistics

写了27分钟,一遍过:)
写了27分钟是怀疑它到底是不是那么简单,想了好久有没有坑qwq
直接输出50个p50,45个p95,4个p99,和一个p99 + 1即可qwq

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int a, b, c;

int main () {
	cin >> a >> b >> c;
	cout << "100\n";
	for (int i = 1; i <= 50; i++) {
		cout << a << ' ';
	}
	for (int i = 51; i <= 95; i++) {
		cout << b << ' ';
	}
	for (int i = 96; i <= 99; i++) {
		cout << c << ' ';
	}
	cout << c + 1;
	return 0;
}

D - Matrix Construction

写了1.5h,一遍过:)
好难啊qwq
我想了1.25h,没想出来,只想到n或者m为偶数时可以按顺序填qwq
还是题解好看:)
题解:沿着对角线按顺序填:)
这几年的OI都白学了的感觉qwq

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int t, n, m, a[1010][1010];

int main () {
	for (cin >> t; t--;) {
		cin >> n >> m;
		cout << "YES\n";
		int x = 1, y = 1;
		for (int i = 1; i <= n * m; i++) {
			a[x][y] = i;
			x++;
			y--;
			if (x > n || y < 1) {
				int tmp = x + y + 1;
				x = max(1, tmp - m);
				y = tmp - x;
			}
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				cout << a[i][j] << ' ';
			}
			cout << "\n";
		}
	}
	return 0;
}

涨经验了,构造矩阵的题还可以斜着填数:)
当然还是要从题目的需求出发去想

E - 直径与最大独立集

写了可能是2h,WA2六发qwq我心态崩了
最后的图就是一个菊花+一条链,那就直接枚举菊花有多大呗。菊花的中心是1,所以就枚举有多少个与1相连的节点(假设有x个),那么只要x+(n−x−1)/2==2+n−x−1x + (n - x - 1) / 2 == 2 + n - x - 1就是合法的。如果直径长了1,就把链的末尾的点挂到链的头上的前面。(这是我WA的根本原因qwq)

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int t, n;

int main () {
	for (cin >> t; t--;) {
		cin >> n;
		int f = 0;
		if (n == 4) {
			cout << "-1\n";
			continue;
		}
		if ((n + 1) / 2 == n - 1) {
			for (int i = 2; i <= n; i++) {
				cout << i - 1 << ' ' << i << "\n";
			}
			continue;
		}
		for (int i = 2; i < n; i++) {
			if (i + (n - i - 1) / 2 == 2 + n - i - 1) {
				for (int j = 2; j <= i + 1; j++) {
					cout << "1 " << j << "\n";
				}
				for (int j = i + 2; j <= n; j++) {
					cout << j - 1 << ' ' << j << "\n";
				}
				f = 1;
				break;
			}
		}
		if (f) continue;
		for (int i = 2; i < n - 1; i++) {
			if (i + (n - i - 1) / 2 + 1 == 2 + n - i - 1 && ((n - i - 1) & 1)) {
				for (int j = 2; j <= i + 1; j++) {
					cout << "1 " << j << "\n";
				}
				for (int j = i + 2; j < n; j++) {
					cout << j - 1 << ' ' << j << "\n";
				}
				cout << i + 1 << ' ' << n << "\n";
				f = 1;
				break;
			}
		}
		if (!f) {
			cout << "-1\n";
		}
	}
	return 0;
}

F - Be Positive

写了15分钟,一遍过:)
这题我好像做过,但之前没搞懂为什么这么构造
正好今天把它搞定叻!!:)
肯定先放1,然后放能放的里面最小的,一定能构造出来。
不难发现(其实是wyn表达能力太菜写不出来为什么),按顺序放的时候,只有到每一个二进制只有1的数前缀异或和才会为0。那就每次到这样的数先就先放它+1再放它就好了:)

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int t, n;

int main () {
	for (cin >> t; t--;) {
		cin >> n;
		int sum = 0;
		for (int i = 1; i < n; i++) {
			sum ^= i;
		}
		if (sum == 0) {
			cout << "impossible\n";
			continue;
		}
		sum = 0;
		for (int i = 0; i < n; i++) {
			if (!(sum ^ i)) {
				cout << i + 1 << ' ' << i << ' ';
				sum = sum ^ i ^ i + 1;
				i++;
			} else {
				cout << i << ' ';
				sum ^= i;
			}
		}
		cout << "\n";
	}
	return 0;
}

G - 不够聪明的贝贝

写了15分钟,WA一发qwq
首先看样例会想到,用正负来让A > B,然后立刻就能想到当n是偶数时全选-1就行。然后wyn凭运气想到了如果n是奇数,就再塞一个2进去,就能AC叻!:)
然鹅为什么WA了一发呢………原来是因为没输出“Yes”啊…………………………(无语

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int t, n;

int main () {
	for (cin >> t; t--;) {
		cin >> n;
		cout << "YES\n";
		if (n & 1) {
			cout << "2 ";
			for (int i = 1; i <= n * 2; i++) {
				cout << "-1 ";
			}
			cout << "\n";
		} else {
			for (int i = 1; i <= n * 2 + 1; i++) {
				cout << "-1 ";
			}
			cout << "\n";
		}
	}
	return 0;
}

H - Bingo 3

写了49分钟,WA一发qwq
我说怎么看着这么熟悉,后来lyf告诉我这是25年武汉场ICPC的I题!我们现场还做出来了,好像就是这个题的气球,等了好久qwq(又想打ICPC了qwq
先在对角线全插进去>=k的,把第一排的那个(a[1][1])填k,然后第一排全填<=k的,剩下的随便填,不重复就行:)
WA一发是因为没判n == k的情况qwq

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int t, n, k, a[100][100];

int main () {
	for (cin >> t; t--;) {
		cin >> n >> k;
		if (k < n) {
			cout << "No\n";
			continue;
		}
		if (n * n - k < n - 1) {
			cout << "No\n";
			continue;
		}
		cout << "Yes\n";
		fill(&a[0][0], &a[n + 1][0], 0);
		for (int i = k; i <= k + n - 1; i++) {
			a[i - k + 1][i - k + 1] = i;
		}
		for (int i = 2; i <= n; i++) {
			a[1][i] = i - 1;
		}
		int tmp = n;
		if (tmp == k) tmp = k + n;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (a[i][j]) {
					cout << a[i][j] << ' ';
				} else {
					cout << tmp << ' ';
					tmp++;
					if (tmp == k) tmp = k + n;
				}
			}
			cout << "\n";
		}
	}
	return 0;
}

我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq
我要打ICPC!qwq

I - Matrix

写了25分钟,WA一发
前面n - 2排全整一样的(第i排填i),后面2排再竖着全搞一样的(前n - 2列第i列填i),最后4个随便填
WA一发是因为看错题叻qwq

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int n, a[60][60], cnt;

int main () {
	cin >> n;
	for (int i = 1; i <= n - 2; i++) {
		for (int j = 1; j <= n; j++) {
			a[i][j] = i;
		}
	}
	for (int i = 1; i <= n; i++) {
		a[n - 1][i] = n - 2 + i;
	}
	for (int i = 1; i <= n - 2; i++) {
		a[n][i] = n - 2 + i;
	}
	a[n][n - 1] = n * 2 - 1;
	a[n][n] = n * 2;
	cout << "Yes\n";
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cout << a[i][j] << ' ';
		}
		cout << "\n";
	}
	return 0;
}

J - Arrow a Row

写了20分钟,一遍过:)
先把左端点定为1,右边的‘>’就一个一个的往左涂色,然后把最后一个的右端点固定住,再用左端点的往右边一个一个跳着涂:)

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int t, ans[100010][2];
string s;

int main () {
	for (cin >> t; t--;) {
		cin >> s;
		int n = s.size();
		s = ' ' + s;
		if (s[1] == '-' || s[n] == '-' || s[n - 1] == '-' || s[n - 2] == '-') {
			cout << "No\n";
			continue;
		}
		int f = 0;
		for (int i = 1; i <= n; i++) {
			if (s[i] == '-') {
				f = 1;
				break;
			}
		}
		if (!f) {
			cout << "No\n";
			continue;
		}
		cout << "Yes ";
		int m = 0;
		ans[++m][0] = 1;
		ans[m][1] = n;
		int tmp = n - 1;
		for (tmp = n - 1; s[tmp - 2] == '>'; tmp--) {
			ans[++m][0] = 1;
			ans[m][1] = tmp;
		}
		tmp++;
		for (int i = 2; i <= tmp - 4; i++) {
			if (s[i] == '>') {
				ans[++m][0] = i;
				ans[m][1] = tmp - i + 1;
			}
		}
		cout << m << "\n";
		for (int i = 1; i <= m; i++) {
			cout << ans[i][0] << ' ' << ans[i][1] << "\n";
		}
	}
	return 0;
}

K - Strips

我明明想出来了,时间不够了还有bug qwq
RE个头啊qwq
@carits 快来帮我调一调它为啥会RE:)

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int t, n, m, k, w, a[100010], b[100010], ans[100010];

int main () {
	for (cin >> t; t--;) {
		cin >> n >> m >> k >> w;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		for (int i = 1; i <= m; i++) {
			cin >> b[i];
		}
		sort(a + 1, a + n + 1);
		sort(b + 1, b + m + 1);
		int f = 1;
		for (int i = 1; i < m; i++) {
			if (b[i + 1] - b[i] - 1 >= k) continue;
			int l = lower_bound(a + 1, a + n + 1, b[i]) - a;
			if (a[k] < b[i + 1] && l <= n) {
				cout << "-1\n";
				f = 0;
				break;
			}
		}
		if (!f) continue;
		int c = 0;
		for (int i = 1; i <= n;) {
			int r = a[i] + k - 1, j = lower_bound(b + 1, b + m + 1, a[i]) - b;
			if (b[j] <= r && j != m + 1) r = b[j] - 1;
			ans[++c] = r - k + 1;
			r++;
			// for (int j = 1; j <= n; j++) {
			// 	cout << a[j] << ' ';
			// }
			// cout << "\n";
			// cout << i << ' ' << r << "\n";
			i = lower_bound(a + 1, a + n + 1, r) - a;
		}
		for (int i = c - 1; i >= 1; i--) {
			if (ans[i + 1] - ans[i] < k) {
				ans[i] = ans[i + 1] - k;
			}
			int j = lower_bound(b + 1, b + m + 1, ans[i]) - b;
			if (b[j] <= ans[i] + k - 1 && j != m + 1){
				cout << "-1\n";
				f = 0;
				break;
			}
			if (ans[i] < 1) {
				cout << "-1\n";
				f = 0;
				break;
			}
		}
		if (!f) continue;
		cout << c << "\n";
		for (int i = 1; i <= c; i++) {
			cout << ans[i] << ' ';
		}
		cout << "\n";
	}
	return 0;
}
原文