Poj 1328 Radar Installation

Source: Internet
Author: User
Tags define local radar

Original title: http://poj.org/problem?id=1328

The topic gives the horizontal ordinate and radius d of N points (islands), requiring the smallest points (radars) to be found on the x-axis, centered on these points, with a radius of D, and containing all the islands.

In the beginning, I would like to make a judgment on the possible location of each radar, use radar to "find" the island, but quickly veto, because the obvious radar may be the location of particularly bad data will be surprisingly much, so want to use the island to "find radar"

Following this analysis, it is found that for each island, it can be scanned into its radar range for X-SQRT (d*d-y*y) (forgive me not to hit the root root) to X+sqrt (d*d-y*y) so that we can turn the problem into a number of

Interval, each interval contains at least one point, requiring the fewest number of points. This is the problem of the interval point, (no wonder is put into greed), first use the above method to get the interval, and then the right endpoint from small to large sort, starting from the first interval,

Each time the last point of the interval is selected, if the point is contained by the next interval, the point continues to be used, otherwise the last point of the next interval is selected.

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <queue>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <string>
  9. #include <algorithm>
  10. #define CLR (arr) memset (arr,0,sizeof(arr))
  11. #define N 1005
  12. #define MOD 1e9+7
  13. #define EPS 1E-6
  14. //#define LOCAL
  15. typedef LONG long ll;
  16. using namespace std;
  17. int n,d;
  18. typedef struct range{
  19. Double L
  20. Double R
  21. }range;
  22. Range Ran[n];
  23. int cmp (const void *a,const void*b) {
  24. return ((range*) a)->r > ((range*) b)->r?1:-1; //There is a pit, use a quick row to sort floating-point numbers using a method that is slightly different from an integer, the hole is not met with sort.
  25. }
  26. int work () {
  27. double cur=ran[0]. R
  28. int Ans=1;
  29. for (int i=1;i<n;i++) {
  30. if (Ran[i]. L>cur) {
  31. Cur=ran[i]. R
  32. ans++;
  33. }
  34. }
  35. return ans;
  36. }
  37. int Main ()
  38. {
  39. #ifdef LOCAL
  40. Freopen ("input.txt", "R", stdin);
  41. //freopen ("Output.txt", "w", stdout);
  42. #endif
  43. int T=1,flag;
  44. double t,x,y;
  45. while (scanf ("%d%d", &n,&d), n| | D) {
  46. flag=1;
  47. for (int i=0;i<n;i++) {
  48. scanf ("%lf%lf", &x,&y);
  49. if (flag&&y<=d&&d>0&&y>=0) {//This is another pit, Y and D's various pit fathers, but the strange thing is to remove the y>=0 can also AC, but the time has slowed down.
  50. T=SQRT (D*d-y*y);
  51. Ran[i]. L=x-t;
  52. Ran[i]. R=x+t;
  53. }
  54. else flag=0;
  55. }
  56. if (flag) Qsort (ran,n,sizeof(ran[0]), CMP);
  57. printf ("Case%d:%d\n", T++,flag?work ():-1);
  58. }
  59. return 0;
  60. }

Because I did the problem of the interval point of view, the code quickly came out, but because the first useless double was a pit, because the quick row of the floating point of the pit has been WA once (>﹏<) I think it's time to turn sort,

All angles seem to be more convenient. By the way thank you for this link: http://blog.163.com/yuhua_kui/blog/static/9679964420142195442766/;

Tomorrow will be back to school, I hate long-distance.

Poj 1328 Radar Installation

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.