$stl$大法好
by Foofish @ 2020-08-21 16:04:25
@[lilong](/user/180406) 排序函数用stl的sort,这个虽然常数大,但是对付一般的题已经足够。
如果一定要自己写的话,推荐归并,比较稳定。
by WanderingTrader @ 2020-08-21 16:05:42
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>inline void R(T& t){
t=0; register char ch=getchar();
while(!('0'<=ch&&ch<='9')){ if(ch=='-') t*=-1; ch=getchar(); }
while(('0'<=ch&&ch<='9')){ t=((t<<1)+(t<<3))+ch-'0'; ch=getchar(); }
}
template <typename T,typename... Args> inline void R(T& t, Args&... args){R(t);R(args...);}
template <typename T>inline void W(T x){
if(x<0) putchar('-'),x=~(x-1); int s[30],top=0; while(x) s[++top]=x%10,x/=10;
if(!top) s[++top]=0; while(top) putchar(s[top--]+'0');
}
int n,ans,rtime;
pair<int,int>a[100086];
int main()
{
R(n);
for(int i=1;i<=n;++i)
R(a[i].second,a[i].first);
sort(a+1,a+n+1);
for(int i=1;i<=n;++i){
if(a[i].second<rtime) continue;
rtime=a[i].first;
ans++;
}
cout<<ans<<endl;
return 0;
}
```
刚水了一发A了
by Foofish @ 2020-08-21 16:07:52
让我试一下
by lilong @ 2020-08-21 16:18:39
@[zycany](/user/270791) 可是起始时间也要交换啊
by lilong @ 2020-08-21 16:19:21
@[lilong](/user/180406) 写结构体,然后自己定义比较函数
by WanderingTrader @ 2020-08-21 16:21:22
```cpp
struct node
{
int a,b;
bool operator < (const node& u) const
{
return /*code here*/;
}
};
by WanderingTrader @ 2020-08-21 16:22:27
@[Foofish](/user/203453) @[zycany](/user/270791) 我AC了,谢谢
by lilong @ 2020-08-21 16:24:30