跳到正文

个人记录

兰华杯赛后总结

wangxinwangxin约 8 分钟
原文
文章信息与版本

文章信息

发布
2026年5月9日
收录
2026年5月9日
更新
2026年12月1日
篇幅
约 8 分钟

版本

  1. v5当前
  2. v4
  3. v3
  4. v2
更早的 1 个版本
  1. v1

                                                                                                               −−−−2026.5.9\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ----2026.5.9

一、赛时表现

预计得分: 100+100+0+100=300100 + 100 + 0 + 100 = 300

实际得分: 100+91+0+0=191100 + 91 + 0 + 0 = 191

时间分配: 30 min+45 min+ 45min以下+60 min以上=3h15min30\ min + 45\ min + \ 45min 以下 + 60\ min以上 = 3h15min

T1\Large_{T1}

赛时思路:

使用一个 map 来储存牛语中的各个字母的次序, 当奶牛唱的字母严格大于上一个字母的次序时,奶牛一定唱了一首新歌.

ACAC思路

同赛时思路.

表现:

表现一般, 1min1min 想出思路,打代码 5min5min ,调代码 40min40min .

时间原因:

Dve-c++的在线编译功能只允许一行内的数据长度在 500500 以内,直接 copycopy 会漏数据,导致正确代码一直无法输出正确答案.

CodeCode
C++
#include <bits/stdc++.h>
#define int long long
#define INF 1000000000000
#define N 100001
using namespace std;
string s, str;
map<char, int> mp;
int ans = 0;
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> s >> str;
	for (int i = 0 ; i < s.size() ; ++i) mp[s[i]] = i;
    ans = 1;
	for (int i = 0 ; i < str.size() ; ++i) {
		if (mp[str[i]] <= mp[str[i - 1]]) {
			ans++;
		}
	}
	cout << ans;
	return 0;
}

T2\Large_{T2}

赛时思路:

直接对奇偶数量进行错误的模拟,加入不知名代码,最终测了几个样例居然对了.

91pts Code91pts\ Code
C++
#include <bits/stdc++.h>
#define INF 1000000000000
#define N 100001
using namespace std;
int n, a[N], ans, vis[N];
int zero, one;
signed main() {
	//freopen("photo.in","r",stdin);
	//freopen("photo.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1 ; i <= n ; ++i) {
		cin >> a[i];
		a[i] = a[i] % 2;
		if (a[i] == 0) {
			zero++;
		} else {
			one++;
		}
	}
	int ned = 0;
	while (true) {
		if (ned == 0) {
			bool ok = false;
			if (zero != 0) {
				zero--;
				ans++;
				ok = true;
			} else if (one >= 2){
				one -= 2;
				ans++;
				ok = true;
			}
			if (!ok) {
				break;
			}
		} else {
			if (one > 0) {
				one--;
				ans++;
			} else {
				break;
			}
		}
		ned = 1 - ned;
	}
	cout << ans;
	return 0;
}

ACAC思路

首先我们读题知道:编号的奇偶性才是关键.

所以我们可以先统计出奇数和偶数各有多少个.

然后会出现两种情况:奇数多,偶数多.

因为公理:

对于任意奇数 aa 和 偶数 bb 有

a+b  mod 2=1a + b \ \bmod 2 = 1 a+a  mod 2=0a + a \ \bmod 2 = 0 b+b  mod 2=0b + b \ \bmod 2 = 0

所以可以得出解决方案:

  • 奇数多时,将两个奇数相加变成偶数,减少奇数的数量,增加偶数的数量。

  • 偶数多时,将偶数和奇数相加变成奇数,减少偶数的数量,增加奇数的数量。

CodeCode
C++
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, ji, ou, x;
signed main() {
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> x;
		if (x % 2 == 1) ji++;
		else ou++;
	}
	while(ji > ou) {
		ji -= 2;
		ou++;
	}
	if(ou > ji + 1) ou = ji + 1;
	cout << ou + ji;
  	return 0;
}

表现:

思路有误,考虑情况不全,数学 贪心题应多加练习.

T3\Large_{T3}

赛时思路:

二分 + check

check内出错,使用一个latlat维护上一个奶牛,代码应有唐错.

0pts Code0pts\ Code
C++
#include <bits/stdc++.h>
#define int long long
#define INF 1000000000000
#define N 100001
using namespace std;
int n, m, a[N], b[N], ans;
bool check(int d) {
	if (d == 0) {
		return 0;
	}
	int i = 1, lat = a[1];
	while (true) {
		if (lat + d <= b[i]) {
			lat = lat + d;
		} else {
			lat = lat + d;
			bool yes = false;
			for (int j = i + 1 ; j <= m; ++j) {
				if (a[j] > lat) {
					i = j;
					lat = a[j];
					yes = true;
					break;
				}
			}
			if (!yes) {
				return 0;
			}
		}
	}
	return 1;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1 ; i <= m ; ++i) {
		cin >> a[i] >> b[i];
	}
	int l = 1, r = 1e18/n, mid;
	while (l <= r) {
		mid = (r - l) / 2 + l;
		if (check(mid)) {
			l = mid + 1;
		} else {
			r = mid - 1;
		}
		ans = mid;
	}
	cout << ans;
	return 0;
}

ACAC思路

二分最短的距离dd. 注意题目中的区间并没有说从小到大给你,因此要先排个序.

用一个变量 latlat 记录目前为止最近的一头牛的位置.

用贪心的思想 每一头牛都是尽可能往前面放(好像原思路错在这).

每枚举一个区间就要结合 latlat 判断一开始可不可以放:

  • 如果不可以放就从 lat+dlat+d 的位置放起,

  • 如果 lat+dlat+d 已经超出该区间了就不放了,

再算还能放几头牛 最后再更新 latlat .

表现:

表现不佳,原因在于二分不牢固.

T4\Large_{T4}

最大的可惜\huge最大的可惜

赛时思路:

使用三维DPDP,第一维 ii 为走访到了第 ii 只荷斯坦牛,第二维 jj 为走访到了第 jj 只根西牛,第三维 kk 为 00 或 11,表示目前以荷斯坦牛或根西牛为结尾.

ACAC思路

同赛时思路.

我不会说我漏了初始化

表现:

dalaodalao 的屎的表现,因为没初始化导致:

291←191291 \leftarrow 191

THE LESSONS OF THE CONTEST

二分,数学,贪心等不熟练.应多练习二分,数学,贪心题目.

原文