题解:P14593 [LNCPC 2025] 猫猫虫打 CF
贪心题。
首先猜一个结论:按
证明:如果
结论得证。
接下来,如果相等,则应该先打
最后,显然如果
于是我们就做完了。复杂度
:::info[code]
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10,mod=1e9+7;
struct node
{
int x,y;
}a[N];
bool cmp(node x,node y)
{
if(max(x.x,x.y)!=max(y.x,y.y)) return max(x.x,x.y)<max(y.x,y.y);
if(x.x!=y.x) return x.x<y.x;
return x.y<y.y;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
sort(a+1,a+n+1,cmp);
int s=0,ans=0;
for(int i=1;i<=n;i++) if(s<=a[i].x) s=max(s,a[i].y),ans++;
cout<<ans;
return 0;
}
:::