期望得分:100+30+100=230

实际得分:60+30+100=190

2017北京国庆刷题Day7 afternoon

排序去重

固定右端点,左端点单调不减

考场上用了二分,没去重,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);
}
View Code

相关文章:

  • 2021-11-13
  • 2021-07-30
  • 2021-12-02
  • 2022-02-13
  • 2021-10-29
  • 2021-11-04
  • 2022-01-24
  • 2021-07-13
猜你喜欢
  • 2021-10-12
  • 2022-02-04
  • 2021-12-11
  • 2022-02-08
  • 2021-07-30
  • 2022-02-11
  • 2021-10-25
相关资源
相似解决方案