0
点赞
收藏
分享

微信扫一扫

NOI2018 模拟 T1

晚安大世界 2022-08-08 阅读 57


​​http://www.elijahqi.win/archives/3876​​​
题意:

给定每个人初始位置和初始速度 求删去k个人的情况下 最长多长时间会相遇

二分答案 算出最后的位置 有多少人相遇就是有多少逆序对 限制需要删除最少的点使得不存在逆序对 那么就是删除除了最长上升子序列以外的点即可

#include<bits/stdc++.h>
#define eps 1e-7
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0,f=1;char ch=gc();
while(!isdigit(ch)) {if(ch=='-') f=-1;ch=gc();}
while(isdigit(ch)) x=x*10+ch-'0',ch=gc();
return x*f;
}
const int N=1e5+10;
struct node{
double p;int id;
}a[N];
struct node1{
int p,v;
}c[N];
int n,k,p[N],v[N],d[N],b[N];
inline bool cmp(const node &a,const node &b){
return a.p<b.p;
}
inline bool cmp1(const node1 &a,const node1 &b){
return a.p<b.p;
}
inline bool check(double t){
for (int i=1;i<=n;++i) a[i].p=p[i]+v[i]*t,a[i].id=i;
sort(a+1,a+n+1,cmp);
for (int i=1;i<=n;++i) d[i]=a[i].id;
memset(b,0x3f,sizeof(b));int res=0;b[0]=0;
for (int i=1;i<=n;++i){
int l=1,r=n;
while(l<=r){
int mid=l+r>>1;
if (b[mid]<d[i]) l=mid+1;else r=mid-1;
}
res=max(res,r+1);b[r+1]=min(b[r+1],d[i]);
}return n-res<=k;
}
int main(){
freopen("a.in","r",stdin);
n=read();k=read();
for (int i=1;i<=n;++i) c[i].p=read(),c[i].v=read();
sort(c+1,c+n+1,cmp1);
for (int i=1;i<=n;++i) p[i]=c[i].p,v[i]=c[i].v;
double l=0,r=2e9;
while(abs(r-l)>eps){
double mid=(l+r)/2;
if(check(mid)) l=mid;else r=mid;
}if (abs(2e9-l)<eps) puts("Forever");else printf("%f\n",l);
return 0;
}


举报

相关推荐

0 条评论