http://poj.org/problem?id=2318
___________________________________________________
The main idea: a box is divided into several sections of the board, give some toys coordinates, ask each interval has several toys.
For each toy, since the input interval is orderly, use a two-point plank to determine which interval a toy is in.
___________________________________________________
1 Program Stone;2 varI,n,m,x1,x2,y1,y2,xi,yi:longint;3Ui,li:Array[0..10000] ofLongint;4AnsArray[0..10000] ofLongint;5 procedureInit;6 varI,j,k:longint;7 begin8 readln (n,m,x1,y1,x2,y2);9ui[0]:=x1;li[0]:=X1;Tenui[n+1]:=x2;li[n+1]:=x2; One ifn=0 ThenHalt; A fori:=1 toN Doreadln (Ui[i],li[i]); - End; -Function Cross (x1,y1,x2,y2,x3,y3,x4,y4:longint): Longint; //Cross Product the begin -cross:= (x2-x1) * (y4-y3)-(y2-y1) * (x4-x3); - End; - functionEF (x,y:longint): Longint; + varI,j,k,left,right,mid:longint; - begin +left:=0; right:=n+1; A whileleft+1<right Do at begin -mid:= (Left+right)Div 2; -k:=Cross (li[mid],y2,ui[mid],y1,li[mid],y2,x,y); - ifk<0 Thenleft:=mid; - ifK>0 Thenright:=mid; - End; inef:=Left ; - End; to Procedure Print; + varI:longint; - begin the fori:=0 toN Do *Writeln (I,': ', Ans[i]); $ Writeln;Panax NotoginsengFillchar (ans,sizeof (ans),0); - End; the Begin +Assign (input,'input.in'); reset (input); A whileTrue Do the begin + Init; - fori:=1 toM Do $ begin $ readln (xi,yi); - Inc (ANS[EF (Xi,yi)); - End; the Print; - End;Wuyi End. the -
POJ 2318 TOYS 2012-01-11