跳到正文

个人记录

2026.03.03

akaryan约 14 分钟
原文

这是 2026年3月4日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年3月3日
收录
2026年3月4日
更新
2026年11月18日
篇幅
约 14 分钟
获赞
1

版本

  1. v2当前
  2. v1

测试情况

题目估分实际
A\texttt{A}100pts\texttt{100pts}40pts\texttt{40pts}
B\texttt{B}100pts\texttt{100pts}100pts\texttt{100pts}
C\texttt{C}10pts\texttt{10pts}10pts\texttt{10pts}
D\texttt{D}30pts\texttt{30pts}30pts\texttt{30pts}
总分240pts\texttt{240pts}180pts\texttt{180pts}

又是挂分的一天。

A

题目 Luogu P8324

分成 22 个部分,分别统计两边的原子数,最后判断是否相等即可。

时间复杂度:O(nl)O(nl)。( ll 为字符串 ss 的长度)

挂分原因

处理数字原子时,没有跳过当前的位置,反而重复计算了当前位置。

AC code
C++
/*
writer:akaryan
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define Int __int128
#define db double
#define ldb long double
#define inf (1 << 30)
#define INF (1LL << 60LL)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin() , (x).end()
#define bug(x) cout << #x << " = " << x << '\n'
using namespace std;
const int N = 2e5 + 10 , M = 2e5 + 10;
const int mod = 998244353;
ll T , x , l , pos , flag;
string s;
map<ll , ll> mp , mp2;
inline void solve(){	
	cin >> s , l = s.size() , s = ' ' + s , mp.clear() , mp2.clear() , x = 1 , pos = flag = 0;
	for (int i = 1 ; i <= l ; i ++) if (s[i] == '>') pos = i;
	for (int i = 1 ; i < pos - 1 ; i ++){
		if (s[i] == '+'){
			x = 1;
			continue;
		}
		if (s[i] >= '0' && s[i] <= '9') x = (s[i] - '0');
		else if (s[i] >= 'A' && s[i] <= 'Z'){
			if (i + 1 < pos - 1 && s[i + 1] >= '0' && s[i + 1] <= '9') mp[s[i] - 'A'] += (s[i + 1] - '0') * x , i ++;
			else mp[s[i] - 'A'] += x;
		}
	}
	x = 1;
	for (int i = pos + 1 ; i <= l ; i ++){
		if (s[i] == '+'){
			x = 1;
			continue;
		}
		if (s[i] >= '0' && s[i] <= '9') x = (s[i] - '0');
		else if (s[i] >= 'A' && s[i] <= 'Z'){
			if (i + 1 <= l && s[i + 1] >= '0' && s[i + 1] <= '9') mp2[s[i] - 'A'] += (s[i + 1] - '0') * x , i ++;
			else mp2[s[i] - 'A'] += x;
		}
	}
	for (int i = 0 ; i <= 25 ; i ++) if (mp[i] != mp2[i]) flag = 1;
	cout << (!flag ? "DA" : "NE") << '\n';
}
int main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) , cin >> T;
	while(T --) solve();
	return 0;
}

B

题目 Luogu P13422

我们想要空杯子的数量最大,应该要尽可能选择当前容积较大的杯子进行填充。所以我们先将杯子的容积从大到小排序,然后依次将液体倒入当前容积较大的杯子中,直到液体被分配完。最后未被分配液体的杯子即为空杯子的数量。

时间复杂度:O(nlog⁡n)O(n \log n)。

AC code
C++
/*
writer:akaryan
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define Int __int128
#define db double
#define ldb long double
#define inf (1 << 30)
#define INF (0x3f3f3f3f3f3f3f3f)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin() , (x).end()
#define bug(x) cout << #x << " = " << x << '\n'
using namespace std;
const int N = (1 << 21) , M = 2e5 + 10;
const int mod = 998244353;
ll n , i = 1 , x , ans , pos , lst;
map<ll , ll> mp;
struct Node{
	ll x , val;
}a[N]; 
inline bool cmp(const Node &x , const Node &y){
	return (x.x > y.x) || (x.x == y.x && x.val > y.val);
}
inline void solve(){
	cin >> n , pos = n;
	for (int i = 1 ; i <= n ; i ++) cin >> x >> a[i].x , ans += x , a[i].val = i;
	sort(a + 1 , a + n + 1 , cmp);//从大到小排序
	while(ans) lst = min(a[i].x , ans) , ans -= lst , mp[a[i].val] = lst , pos -- , i ++;
	cout << pos << '\n';
	for (int i = 1 ; i <= n ; i ++) cout << mp[i] << ' ';
}
int main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	solve();
	return 0;
}

C

题目 Luogu P14781

这题的思路比较巧妙。

首先,既然我们想要计算最少线段数,那么我们可以反过来想,用总共的线段数 - 可合并的线段数,总共的线段数为 (n+2)+∑i=1nbi(n+2)+\sum\limits_{i=1}^{n}b_i。

然后,我们令 sumisum_i 表示相邻柱子可供共享的水平线数,得到公式:

sumi=min⁡(bi−1ai×bi−1gcd⁡(ai×bi−1,ai−1×bi),biai−1×bigcd⁡(ai×bi−1,ai−1×bi))sum_i = \min\left( \frac{b_{i-1}}{\frac{a_i \times b_{i-1}}{\gcd(a_i \times b_{i-1}, a_{i-1} \times b_i)}}, \frac{b_i}{\frac{a_{i-1} \times b_i}{\gcd(a_i \times b_{i-1}, a_{i-1} \times b_i)}} \right)

接着,我们将式子通分一下,得到:

sumi=min⁡(gcd⁡(ai×bi−1,ai−1×bi)ai,gcd⁡(ai×bi−1,ai−1×bi)ai−1)sum_i = \min\left( \frac{\gcd(a_i \times b_{i-1}, a_{i-1} \times b_i)}{a_i}, \frac{\gcd(a_i \times b_{i-1}, a_{i-1} \times b_i)}{a_{i-1}} \right)

也就是:

sumi=gcd⁡(ai×bi−1,ai−1×bi)max⁡(ai,ai−1)sum_i = \frac{\gcd(a_i \times b_{i-1}, a_{i-1} \times b_i)}{\max(a_i, a_{i-1})}

所以,最终答案为:

ans=(n+2)+∑i=1nbi−∑i=2nsumi\text{ans} = (n+2)+\sum_{i=1}^n b_i - \sum_{i=2}^{n} sum_i

时间复杂度:O(nlog⁡(max⁡1≤i≤n{ai,bi}))O(n \log (\max\limits_{1 \leq i \leq n} \{a_i, b_i\}))。

AC code
C++
/*
writer:akaryan
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define Int __int128
#define db double
#define ldb long double
#define inf (1 << 30)
#define INF (1LL << 60LL)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin() , (x).end()
#define bug(x) cout << #x << " = " << x << '\n'
using namespace std;
const int N = 2e5 + 10 , M = 2e5 + 10;
const int mod = 998244353;
ll n , ans , a[N] , b[N] , s[N];
inline ll gcd(ll a , ll b){
	return (!b ? a : gcd(b , a % b));
}
inline ll lcm(ll a , ll b){
	return a / gcd(a , b) * b;
}
inline void solve(){
	cin >> n , ans = n + 2;
	for (int i = 1 ; i <= n ; i ++) cin >> a[i];
	for (int i = 1 ; i <= n ; i ++) cin >> b[i] , ans += b[i];
	for (int i = 2 ; i <= n ; i ++) ans -= (gcd(a[i] * b[i - 1] , a[i - 1] * b[i])) / max(a[i] , a[i - 1]);
	cout << ans << '\n';
}
int main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	solve();
	return 0;
}

D

题目 Luogu P9178

首先,题目要求我们求出最大哈明距离,那我们可以将题目转化 mm 减最小哈明距离,接着每次翻转 11 位相当于走 11 步,这个问题就被我们迎刃而解啦!最后跑一遍多源多汇 BFS 即可。

时间复杂度:O(m×2m)O(m \times 2^m)。

AC code
C++
/*
writer:akaryan
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define Int __int128
#define db double
#define ldb long double
#define inf (1 << 30)
#define INF (1LL << 60LL)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin() , (x).end()
#define bug(x) cout << #x << " = " << x << '\n'
using namespace std;
const int N = (1 << 21) , M = 2e5 + 10;
const int mod = 998244353;
ll n , m , a[N] , dis[N];
bool vis[N];
queue<ll> q;
inline void solve(){
	cin >> n >> m;
	for (int i = 0 ; i <= N ; i ++) dis[i] = INF;
	for (int i = 1 ; i <= n ; i ++) cin >> a[i] , q.push(a[i]) , dis[a[i]] = 0 , vis[a[i]] = 1;
	while (!q.empty()){
		auto x = q.front();
		q.pop();
		for (int i = 0 ; i <= m ; i ++) if (!vis[x ^ (1 << i)]) dis[x ^ (1 << i)] = dis[x] + 1 , vis[x ^ (1 << i)] = 1 , q.push((x ^ (1 << i)));
	}
	for (int i = 1 ; i <= n ; i ++) cout << m - dis[((1 << (m + 1)) - 1) ^ a[i]] + 1 << ' ';
}
int main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	solve();
	return 0;
}

总结

A\texttt{A} 题因为细节问题挂了 60pts\texttt{60pts},通过这次考试让我深刻认识到细节的重要性,我也会努力地提升自己的能力,继续加油!

Thanks for reading.\texttt{Thanks for reading.}