Description There's a racing game going on, and there's a total of n cars on the pitch, called a g1,g2......gn, respectively. The track is an infinitely long line. Initially, GI is located at the starting point of the Forward Ki. After the game starts, the vehicle GI will travel at a constant speed of VI units per second. In this game, if a car was once in the lead (i.e. no other car racing in front of him), the car will be awarded at the end, and there is no need to worry about collisions during the game. Now given the starting position and speed of all the cars, your task is to figure out which cars will win the prize. The first line of input has a positive integer n indicating the number of cars. The next line gives n integers, giving the starting position of N cars in order. The next line gives n integers, in order to give the constant speed of n cars. Output outputs consist of two lines, the number of first-prize racers. The second line outputs the number of the winning car in order from small to large, separated by a space, and note that the last number is followed by no spaces. Sample Input4
1 1 0 0
15 16 10 20
Sample Output3
1 2 4
HINT
For 100% data n<=10000, 0<=ki<=10^9, 0<=vi<=10^9
Exercises
Set the position as Yi,yi=ki+ti*v, as y about T in a function image, there is no doubt that the T-moment leading car is t=t when Yi's largest function.
In this way, the original problem becomes a semi-planar model, the solution is the same as bzoj1007[hnoi2008] horizontal visible line.
Code:
varI,j,l,r,n,m:longint; K,b,a,s:Array[0..10001] ofLongint; V:Array[0..10001] ofBoolean; Flag:boolean;proceduresort (l,r:longint);varI,j,x,x2,y:longint;beginI:=l; J:=r; x:=k[(L+r)Div 2]; x2:=b[(L+r)Div 2]; Repeat while(k[i]<x)or((k[i]=x) and(B[I]<X2)) DoInc (I); while(X<k[j])or((X=k[j]) and(X2<b[j])) DoDec (j); ifI<=j Then beginy:=k[i]; K[I]:=K[J]; k[j]:=y; Y:=b[i]; B[I]:=B[J]; b[j]:=y; Y:=a[i]; A[I]:=A[J]; a[j]:=y; Inc (I); Dec (j); End; untilI>J; ifI<r Thensort (i,r); ifJ>l Thensort (l,j);End;beginREADLN (n); fori:=1 toN Doread (b[i]); fori:=1 toN Doread (k[i]); fori:=1 toN Doa[i]:=i; Sort (1, N); R:=1; i:=1; while(i<n) and(k[i]=k[i+1]) and(b[i]<>b[i+1]) DoInc (I); s[1]:=i; Inc (I); k[0]:=-1; whileI<=n Do begin while(r>0) and(K[i]=k[s[r]]) and(B[i]<>b[s[r]]) DoDec (r); ifK[I]<>K[S[R]] Then begin while(r>0) and((B[i]-b[s[r])/(K[s[r]]-k[i]) <0) DoDec (r); while(r>1) and((B[i]-b[s[r])/(K[s[r]]-k[i]) <(B[s[r]]-b[s[r-1]])/(k[s[r-1]]-K[S[R])) DoDec (r); End; Inc (R); S[R]:=I; Inc (i); End; Fillchar (v,sizeof (v), false); Writeln (R); fori:=1 toR Dov[a[s[i]]]:=true; Flag:=false; fori:=1 toN Do ifV[i] Then begin if notFlag Then beginflag:=true; write (i); End ElseWrite' ', i); End; Writeln;End.
View Code
BZOJ3190[JLOI2013] Racing