传送门
计算几何经典题。
显然可以做出每个人的
x
−
t
x-t
x−t图像,发现就是求半平面交上的点。
注意舍去交点不在一象限的点。
代码:
#include<bits/stdc++.h>
#define N 10005
using namespace std;
inline int read(){
int ans=0;
char ch=getchar();
while(!isdigit(ch))ch=getchar();
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
return ans;
}
int n,top,stk[N],ans[N],tot=0;
struct Line{int g,v,id;}l[N];
inline bool cmp(Line a,Line b){return a.v==b.v?a.g>b.g:a.v<b.v;}
inline double slope(int i,int j){return l[i].v==l[j].v?1e18:(double)((double)l[i].g-l[j].g)/((double)l[j].v-l[i].v);}
int main(){
n=read();
for(int i=1;i<=n;++i)l[i].g=read();
for(int i=1;i<=n;++i)l[i].v=read(),l[i].id=i;
sort(l+1,l+n+1,cmp);
stk[++top]=1;
for(int i=2;i<=n;++i){
if(l[i].v==l[i-1].v&&l[i].g<l[i-1].g)continue;
while(top>=2&&slope(stk[top-1],stk[top])>slope(stk[top],i))--top;
stk[++top]=i;
}
for(int i=2;i<=top;++i)if(slope(stk[i-1],stk[i])>=0)ans[++tot]=l[stk[i-1]].id;
ans[++tot]=l[stk[top]].id;
sort(ans+1,ans+tot+1);
printf("%d\n",tot);
for(int i=1;i<=tot;++i)printf("%d ",ans[i]);
return 0;
}