POJ 2318 TOYS 2012-01-11

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.