Poj 2318 toys

Source: Internet
Author: User

Poj_2318

You can use the cross product to determine the left or right of the online segment.

# Include <stdio. h>
# Include < String . H>
# Define Maxd 5010
Int N, m, X1, Y1, X2, Y2, a [maxd], B [maxd], H [maxd];
Long Long Int Det ( Int X1, Int Y1,Int X2, Int Y2)
{
Return ( Long Long Int ) X1 * Y2 -( Long Long Int ) X2 * Y1;
}
Void Init ()
{
Int I, J, K;
A [0 ] = B [ 0 ] = X1;
For (I = 1 ; I <= N; I ++)
Scanf ( " % D " , & A [I], & B [I]);
}
Void Solve ()
{
Int I, J, K, X, Y, mid, Min, Max;
Memset (H, 0 ,Sizeof (H [ 0 ]) * (N + 1 ));
For (I = 0 ; I <m; I ++)
{
Scanf ( " % D " , & X, & Y );
Min = 0 , Max = N + 1 ;
For (;;)
{
Mid = (max-min )/ 2 + Min;
If (Mid = min)
Break ;
If (Det (A [Mid]-B [Mid], Y1-Y2, X-B [Mid], Y-Y2) < 0 )
Min = mid;
Else
Max = mid;
}
++ H [Mid];
}
For (I =0 ; I <= N; I ++)
Printf ( " % D: % d \ n " , I, H [I]);
}
Int Main ()
{
Int T = 0 ;
While (Scanf ( " % D " , & N, & M, & X1, & Y1, & X2, & Y2) =6 )
{
If (T ++)
Printf ( " \ N " );
Init ();
Solve ();
}
Return 0 ;
}


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.