zoukankan      html  css  js  c++  java
  • nyist 287 Redar

    题大意:

    给你n 和r;r表示最大半径不能超过这个数

    后面给定n个点的坐标,y 大于零,

    输出如果不能全部覆盖输出  -1 

    一开始还以为只要有一个满足就输出-1  结果我错了

    这是一道区间选点问题

    #include<iostream>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    const int N=1010;
    typedef struct x_y
    {
        double x,y;
    }X_Y;
    X_Y a[N];
    int fun(X_Y a,X_Y b)
    {
        if(a.x<b.x) return 1;
        else return 0;
    }
    int main()
    {
        int n,r;
        int t = 1;
        while(1)
        {
            double b[N];
            cin>>n>>r;
            if(n==0&&r==0)  break;
            double x1;
            int i,count=1;
            for( i = 0; i < n; i++)
            {
            cin>>x1>>b[i];
            double len = sqrt((r*r)-(b[i]*b[i]));
            a[i].x = x1 - len;
            a[i].y = x1 + len;
            }
            int flag = 1;
            for( i = 0; i < n; i++)
               if(b[i] > r)
               {
                  cout<<"Case "<<t<<": -1\n";
                   flag = 0;
                   break;
               }

            if(flag)
            {
                sort(a,a+n,fun);
                double yy = a[0].y;
                for( i = 1; i < n; i++ )
                    if(a[i].x>yy)
                    {
                       count++;
                        yy = a[i].y;
                    }
                    else
                    {
                        if(a[i].y<yy)
                           yy = a[i].y;
                    }
                    cout<<"Case "<<t<<": "<<count<<"\n";
            }
            t++;

        }
        return 0;

    }

  • 相关阅读:
    LeetCode Find Duplicate File in System
    LeetCode 681. Next Closest Time
    LeetCode 678. Valid Parenthesis String
    LeetCode 616. Add Bold Tag in String
    LeetCode 639. Decode Ways II
    LeetCode 536. Construct Binary Tree from String
    LeetCode 539. Minimum Time Difference
    LeetCode 635. Design Log Storage System
    LeetCode Split Concatenated Strings
    LeetCode 696. Count Binary Substrings
  • 原文地址:https://www.cnblogs.com/yyroom/p/2789768.html
Copyright © 2011-2022 走看看