跳到正文

个人记录

2026.03.23

akaryan约 13 分钟
原文
文章信息与版本

文章信息

发布
2026年3月23日
收录
2026年3月23日
更新
2026年11月18日
篇幅
约 13 分钟

版本

  1. v2当前
  2. v1

测试情况

题目估分实际
A\texttt{A}100pts\texttt{100pts}100pts\texttt{100pts}
B\texttt{B}100pts\texttt{100pts}100pts\texttt{100pts}
C\texttt{C}100pts\texttt{100pts}100pts\texttt{100pts}
D\texttt{D}50pts\texttt{50pts}50pts\texttt{50pts}
总分350pts\texttt{350pts}350pts\texttt{350pts}

今天没挂分!!!

A

题目 Luogu P8295

题意

给定 NSC 商店和其他 nn 家商店,每家商店的肉肠的价格为 xx 元 yy 克。

求这 n+1n+1 家商店买 10001000 克香肠最少要花多少钱。

思路

模拟。每次更新最小值,最后通过 单价=总价数量单价=\frac{总价}{数量},求出每一克肉肠的价格,最后乘上 10001000 即可。

时间复杂度为 O(n)O(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 (1LL << 60LL)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#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;
int n , x , y , a , b , now , now2;
inline void solve(){
	cin >> x >> y >> n;
	while(n --) cin >> a >> b , now = a * y , now2 = b * x , x = ((now < now2) ? a : x) , y = ((now < now2) ? b : y);//更新最小值
	cout << fixed << setprecision(2) << (db)(1.0 * x / y * 1000) << '\n';//求1000克肉肠的价格
}
int main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	solve();
	return 0;
}

B

题目 Luogu P13426

题意

给定一个长度为 nn 的字符串,其中 + 表示第 ii 天的资产增加,- 表示第 ii 天的资产减少,= 表示第 ii 天资产不变。

  • 如果第 ii 天的净资产上涨,他会在当天开始时的净资产对应的行画 /。
  • 如果第 ii 天的净资产下跌,他会在当天开始时的净资产对应的行画 \。
  • 如果第 ii 天的净资产不变,他会在当天开始时的净资产对应的行画 -。

求矩阵大小最小的公司资产的变化示意图。

思路

用 pospos 记录当前所在行的资产值。

因为资产值可能有变化,所以我们需要知道最高行和最低行,才能确定矩阵范围。

每天根据符号,在数组的第 pospos 行第 ii 列放字符,然后更新最高行和最低行。

最后从最高行到最低行输出矩阵即可。

Trick

由于 pospos 可能会变成负数,所以要将 pospos 初始为较大的数。

时间复杂度约为 O(n2)O(n^2)。

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 pb push_back
#define eb emplace_back
#define fi first
#define se second
#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 , x , y = 1145141919 , pos = 110;
string s;
char ch[N][N];
inline void solve(){	
	cin >> n >> s , s = ' ' + s , memset(ch , '.' , sizeof(ch));
	for (int i = 1 ; i <= n ; i ++){
		if (s[i] == '+') x = max(x , pos) , y = min(y , pos) , ch[pos ++][i] = '/';//资产上涨
		else if (s[i] == '-') ch[-- pos][i] = '\\' , x = max(x , pos) , y = min(y , pos);//资产下跌
		else if (s[i] == '=') x = max(x , pos) , y = min(y , pos) , ch[pos][i] = '_';//资产不变
	}
	for (int i = x ; i >= y ; i --){
		for (int j = 1 ; j <= n ; j ++) cout << ch[i][j];
		cout << '\n';
	}
}
int main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	solve();
	return 0;
}

C

题目 Luogu P9909

题意

给定一个 n×n×nn\times n\times n 的立方体,给定起点坐标和终点坐标,求从起点到终点最少走多少步。

思路

BFS 板板题。

和二维的 BFS 差不多,区别就在于多了一维和不能斜着走。

时间复杂度为 O(n3)O(n^3)。

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 pb push_back
#define eb emplace_back
#define fi first
#define se second
#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;
const int dx[] = {1 , -1 , 0 , 0 , 0 , 0} , dy[] = {0 , 0 , 1 , -1 , 0 , 0} , dz[] = {0 , 0 , 0 , 0 , 1 , -1};
ll n , sx , sy , sz , ex , ey , ez , dis[N][N][N];
char a[N][N][N];
bool vis[N][N][N];
struct Node{
	ll x , y , z;
};
queue<Node> q;
inline void bfs(){//bfs求[sx,sy,sz]到[ex,ey,ez]的最短距离
	q.push({sx , sy , sz}) , dis[sx][sy][sz] = 0;
	while(!q.empty()){
		auto x = q.front();
		q.pop();
		for (int i = 0 ; i < 6 ; i ++){
			ll nx = x.x + dx[i] , ny = x.y + dy[i] , nz = x.z + dz[i];
			if (nx >= 1 && nx <= n && ny >= 1 && ny <= n && nz >= 1 && nz <= n && !vis[nx][ny][nz]) dis[nx][ny][nz] = dis[x.x][x.y][x.z] + 1 , vis[nx][ny][nz] = 1 , q.push({nx , ny , nz});
		}
	}
}
inline void solve(){
	cin >> n >> sx >> sy >> sz >> ex >> ey >> ez;
	for (int k = 1 ; k <= n ; k ++) for (int i = 1 ; i <= n ; i ++) for (int j = 1 ; j <= n ; j ++) cin >> a[i][j][k] , vis[i][j][k] = (a[i][j][k] - '0') , dis[i][j][k] = INF;
	bfs() , cout << ((dis[ex][ey][ez] == INF) ? -1 : dis[ex][ey][ez]) << '\n';
}
int main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	solve();
	return 0;
}

D

题目 Luogu P14595

题意

给定 nn 个学生在校的时间段 [li,ri)[l_i,r_i),选择一段连续的上课时间 [L,R)[L,R) 使得至少有 kk 个学生在这段时间内全程在校,求该课能持续的最长时间。

思路

由于我们想让课能持续的时间最长,那么选择刚好 kk 个学生肯定是最优的。因为如果选择了第 k+1k+1 个学生,若该学生的上课时间段为 [L,R)[L,R) 或大于时间段 [L,R)[L,R)。那么答案一定不会变得更优,因为最后的答案一定不会改变,一定为 [L,R)[L,R)。因此选择 kk 个同学维持的时间一定是最长的。

将所有学生的时段按 lil_i 升序排序,再用小根堆维护右端点。当学生总数达到 kk 个时,用堆顶最小右端点计算区间长度并更新最大值:

ans←max⁡(ans,rmin⁡−li)ans \leftarrow \max(ans, r_{\min} - l_i)

最后 ansans 即为答案。

时间复杂度为 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 (1LL << 60LL)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define bug(x) cout << #x << " = " << x << '\n'
using namespace std;
const int N = 3e5 + 10 , M = 2e5 + 10;
const int mod = 998244353;
ll n , k , ans;
priority_queue<ll , vector<ll> , greater<ll>> q;//维护小根堆
struct Node{
	ll l , r;
}a[N];
inline void solve(){
	cin >> n >> k;
	for (int i = 1 ; i <= n ; i ++) cin >> a[i].l >> a[i].r;
	sort(a + 1 , a + n + 1 , [&](const Node &x , const Node &y){return x.l < y.l;});//按左端点排序
	for (int i = 1 ; i <= n ; i ++){
		q.push(a[i].r);
		if (q.size() > k) q.pop();
		if (q.size() == k && q.top() >= a[i].l) ans = max(ans , q.top() - a[i].l);
	}
	cout << ans << '\n';
}
int main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	solve();
	return 0;
}

后记

帮 ggy 调题,调到我晚上 1111 点半。/hq/hq/hq

原文