夜晚使人着迷。没有猝死非常感动。

  A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响;对于竖直直线,如果要删一定是删去一段前缀。枚举竖直直线删到哪一条,记一下需要删几条水平线段就可以了。想当然的以为竖直直线横坐标是升序排的,因为这个wa了两发感觉非常惨。

#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,m,line[N],row[N];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
#endif
    n=read(),m=read();
    for (int i=1;i<=n;i++) line[i]=read();line[++n]=1000000000;sort(line+1,line+n+1);
    int t=0;
    for (int i=1;i<=m;i++)
    {
        int x=read(),y=read();read();
        if (x==1) row[++t]=y+1;
    }
    sort(row+1,row+t+1);
    int x=0,cnt=t,ans=n+m;
    for (int i=1;i<=n;i++)
    {
        while (x<t&&row[x+1]<=line[i]) x++,cnt--;
        ans=min(ans,cnt+i-1);
    }
    cout<<ans;
    return 0;
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2021-05-30
  • 2021-08-31
  • 2021-07-29
  • 2021-12-11
猜你喜欢
  • 2022-03-10
  • 2021-12-10
  • 2021-04-28
  • 2021-06-13
  • 2021-09-21
  • 2021-07-10
相关资源
相似解决方案