U479337 YCW的苦恼题解
这道题 很水 很简单,首先,可以推断这是一道贪心题目,经过一些思考可以知道,我们要右端点排序来算有机场考试与某一场考试冲突,计算总共有几个“某一场考试”QAQ
然后又是:
喜闻乐见的代码时刻
#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;
}