期望得分:100+30+100=230
实际得分:60+30+100=190
排序去重
固定右端点,左端点单调不减
考场上用了二分,没去重,60
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; #define N 100001 void read(int &x) { x=0;char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); } } struct node { int a,b; bool operator < (node q) const { if(a!=q.a) return a<q.a; return b<q.b; } bool operator == (node p) const { return a==p.a && b==p.b; } }e[N]; int main() { freopen("card.in","r",stdin); freopen("card.out","w",stdout); int n; read(n); for(int i=1;i<=n;i++) read(e[i].a),read(e[i].b); sort(e+1,e+n+1); int tot=unique(e+1,e+n+1)-e-1; int l,last,mx=0; for(l=1;l<=tot;l++) { if(e[l].a!=e[l-1].a) last=l; while(e[l].b-e[last].b+1>n) last++; mx=max(mx,l-last+1); } printf("%d\n",n-mx); }