# Bzoj3190 [jloi2013]赛车

## 无脑半平面交

Posted by yjjr's blog on February 5, 2018

# 题目

Description

Input 第一行有一个正整数N表示赛车的个数。 接下来一行给出N个整数，按顺序给出N辆赛车的起始位置。 再接下来一行给出N个整数，按顺序给出N辆赛车的恒定速度。

Output

Sample Input 4

1 1 0 0

15 16 10 20

Sample Output 3

1 2 4

HINT

2016.1.17新加数据一组 By Nano_ape

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
#define eps 1e-8
using namespace std;
{
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=1e5+6;
int n,top,ans[maxn];
struct node{
int p,v,id;
friend double Inter(node a,node b){return (double)(a.p-b.p)/(b.v-a.v);}
friend bool operator<(node a,node b){return a.v!=b.v?a.v<b.v:a.p<b.p;}
}c[maxn],que[maxn];
inline bool jud(node a,node b,node t){return Inter(a,b)>Inter(a,t);}
int main()
{
rep(i,1,n)c[i].id=i;
sort(c+1,c+1+n);
top=1;
rep(i,2,n){
if(c[i].v!=c[i-1].v||(c[i].v==c[i-1].v&&c[i].p==c[i-1].p))top++;
c[top]=c[i];
}
n=top;top=0;
que[++top]=c[1];ans[1]=c[1].id;
rep(i,2,n){
while(top>=1&&(Inter(que[top],c[i])<-eps))top--;
while(top>=2&&jud(que[top-1],que[top],c[i]))top--;
que[++top]=c[i],ans[top]=c[i].id;
}
cout<<top<<endl;
sort(ans+1,ans+1+top);
rep(i,1,top)printf("%d%c",ans[i],i!=top?' ':'\n');
return 0;
}