跳到正文

题解

U479337 YCW的苦恼题解

IdleFish约 1 分钟
原文
文章信息与版本

文章信息

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

版本

  1. v1当前

U479337 YCW的苦恼题解

这道题 很水 很简单,首先,可以推断这是一道贪心题目,经过一些思考可以知道,我们要右端点排序来算有机场考试与某一场考试冲突,计算总共有几个“某一场考试”QAQ

然后又是:

喜闻乐见的代码时刻

C++
#include<bits/stdc++.h>
using namespace std;
struct Node{
	int x;
	int y;
}a[100001];
bool cmp(Node o , Node p){
	return o.y<p.y;
}
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
	}
	sort(a+1,a+1+n,cmp);
	int now=-1;
	int ans=0;
	for(int i=1;i<=n;i++){
		if(a[i].x<=now){
			continue;
		}
		else{
			ans++;
			now=a[i].y;
		}
	}
	printf("%d",ans);
	return 0;
}
原文