跳到正文

个人记录

记2025/6/14飞机场惨案

Folden_xiaoming约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 3 分钟
获赞
1

版本

  1. v1当前

在差不多两个月后,我才想起来写这篇文章。

那天学校举办了一场 143143 人参加的大考试,一共 66 道题目,第 kk 道题目价值 100k100k 分。当天我取得了 936936分,rk 4444 的烂成绩。各题得分为:

t1t2t3t4t5t6
1001751371603640

抛开别的低级错误不谈,注意到 t4 只得了 40%40\% 的分。我查看了 std 发现和我的代码几乎一样:

(ps:考场上削弱了一下数据,std 在洛谷上无法 AC)

std:

C++
#include<bits/stdc++.h>
using namespace std;
int g,p,cnt,pos,proot,a[100005];
int f[100005];
void init(int n){
	for(int i=1;i<=n;i++)f[i]=i;
}
int getroot(int u){
	if(f[u]==u)return u;
	return f[u]=getroot(f[u]);
}
void conn(int u,int v){
	f[getroot(u)]=getroot(v);  //u所在的树,挂在v所在的树下
}
int main(){
    cin>>g>>p;
	init(g);
	for(int i=1;i<=p;i++){
		cin>>pos;
		//使用pos所在的树根
		proot=getroot(pos);
		if(proot==0)break;  //无停机坪可用
		cnt++;
		//并将pos所在的树合并至前方一棵树上
		conn(proot,getroot(proot-1));
	}
	cout<<cnt;
    return 0;
}
/*
# P9812 2015 S3  贪心 并查集

贪心:每次都用可使用的最大编号

优化:如何快速跳过已经用掉的大编号 ?
并查集:已经用过的大编号合并至前方小编号

每棵树的树根是可用的停机坪,子节点是不可用的停机坪

可使用停机坪 1-pos
尽量用大的编号,即pos的根
树根使用完毕后,将这棵树挂在前方的一棵树下

*/

my code:

C++
#include<bits/stdc++.h>//AC
using namespace std;
#define int long long
int ga,p,g,f[110000],ans;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>ga>>p;
	for(int i=1;i<=p;i++){
		cin>>g;
		while(f[g]){
			g--;
			if(g==0){
				cout<<ans;
				return 0;
			}
		}
		f[g]=1;
		ans++;
	}
	return 0;
}

可以发现,我在赛时一眼看出了贪心的结论,还自信地挂上了 AC 的注释。

后来,我又看了题面,才注意到有可能有特殊情况,需要在循环结束后判断。

这是我头一次见到让我痛失 240240 分的特判。由于题目背景是机场,故称其为:

飞机场惨案

原文