Poj_1328 radar installation (Greedy)

Source: Internet
Author: User
Tags radar

Vongang original. If any error occurs, please correct it. Reprinted Please note: http://www.cnblogs.com/vongang/

First, find the radar range corresponding to each Island, and then use greedy ideas. Class is a problem of venue layout. (Note: The C-language qsort function may have some errors in floating-point operations. I have contributed countless wa ...)

   

 

# Include <stdio. h>
# Include <stdlib. h>
# Include <math. h>
# Define n 1002
Struct Node
{
Double S;
Double E;
} Num [N];

Int CMP (const void * a, const void * B)
{
Return (* (struct node *) a). S> = (* (struct node *) B). S? 1:-1; // special note !!!
}

Int main ()
{
// Freopen ("data. In", "r", stdin );
Int N, I, CAS = 0;
Int X, Y, R;
While (scanf ("% d", & N, & R )! = EOF)
{
If (n = 0 & R = 0) break;
Int flag = 0;
For (I = 0; I <n; I ++)
{
Scanf ("% d", & X, & Y );
If (Y> r | Y <0) Flag = 1;
Else
{
Num [I]. S = x-SQRT (double) (R * r-y * y ));
Num [I]. E = x + SQRT (double) (R * r-y * y ));
}
}
If (r <0 | flag) {printf ("case % d:-1 \ n", ++ CAS); continue ;}
Qsort (Num, N, sizeof (struct node), CMP );
Double TMP = num [0]. E;
Int COUNT = 1;
For (I = 1; I <n; I ++)
{
If (TMP <num [I]. s)
{
Count ++;
TMP = num [I]. E;
}
Else
{
If (TMP> num [I]. e) TMP = num [I]. E;
}
}
Printf ("case % d: % d \ n", ++ cas, count );
}
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.