对于两辆速度不同的赛车,快的早晚可以超过慢的,超过的时间就是他们初始距离差除以速度差。如果一辆车在超过比他慢的前一辆是就被比他快的后一辆超过了,或者不如比他快的初始位置远,他就永远不会成为第一。所以可以以速度为横坐标,初位置为纵坐标,将车按速度从小到大排序,超过的时间就是斜率的负值。然后单调栈维护一下斜率递减就可以了,可以用叉积来验证。
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=10010;
struct node{
double x,y;
int id;
}p1[N];
int n,top,sta[N],ans[N];
bool f1(node a,node b,node c){
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y)>0;
}
bool cmp(node a,node b){
if(a.x!=b.x)return a.x<b.x;
return a.y<b.y;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%lf",&p1[i].y),p1[i].id=i;
for(int i=1;i<=n;++i)scanf("%lf",&p1[i].x);
sort(p1+1,p1+n+1,cmp);top=0;
for(int i=1;i<=n;++i){
while((top>0&&p1[sta[top]].y<p1[i].y)||(top>1&&f1(p1[sta[top-1]],p1[sta[top]],p1[i])))--top;
sta[++top]=i;
}
printf("%d\n",top);
for(int i=1;i<=top;++i)ans[i]=p1[sta[i]].id;
sort(ans+1,ans+top+1);
for(int i=1;i<top;++i)printf("%d ",ans[i]);
printf("%d",ans[top]);
return 0;
}