zoukankan      html  css  js  c++  java
  • The Cats' Feeding Spots

    The Cats' Feeding Spots

    时间限制:1000ms
    单点时限:1000ms
    内存限制:256MB

    描述

    In Yan Yuan, the Peking University campus, there are many homeless cats. They all live happy lives because students founded a Cat Association to take care of them. Students not only feed them, but also treat their illness and sterilize some of them. Students make many feeding spots for the cats and cats always gather around those spots and make a lot of noise at night. Now the university authorities decide to restrict the number of feeding spots. This is the conversation between an officer and Rose Li, the director of Cat Association, and also a ACMer.

    "Rose, From now on, you can't build any new feeding spots any more. But I want you to keep exactly N feeding spots, and you should make the area which contains the feeding spots as small as possible!"

    "Oh, do you mean that we should find a smallest convex hull which contains N spots?"

    "Convex hull? What is a convex hull? Please speak Chinese!"

    "All right, forget the convex hull. So what do you mean the 'area', what's its shape?"

    "It means... and the shape? Oh... let's do it this way: you can choose any feeding spot as center, and then draw a circle which includes exactly N spots. You should  find the smallest circle of such kind, and then we remove all feeding spots outside that circle."

    Although this way sounds a little bit ridiculous, Rose still writes a program to solve the problem. Can you write the program?

    输入

    The first line is an integer T (T <= 50), meaning the number of test cases.

    Then T lines follow, each describing a test case.

    For each test case:

    Two integer M and N go first(1 <= M, N <= 100), meaning that there are M feeding spots originally and Rose Li has to keep exactly N spots.

    Then M pairs of real numbers follow, each means a coordinate of a feeding spot in Yan Yuan. The range of coordinates is between [-1000,1000]

    输出

    For each test case, print the radius of the smallest circle. Please note that the radius must be an POSITIVE INTEGER and no feeding spots should be located just on the circle because it's hard for the campus gardeners to judge whether they are inside or outside the circle.  If there are no solution, print "-1" instead.

    样例输入
    4
    3 2 0 0 1 0 1.2 0
    2 2 0 0 1 0
    2 1 0 0 1.2 0
    2 1 0 0 1 0
    样例输出
    1
    2
    1
    -1
     
     题意:大学生照看好多猫,设置了几个安置点,现在需要以任意一个安置点为圆心画圆,在圆内有n个点,问这个圆半径最短多少,向上取整画圆,圆内恰好有n个点,边上不能有,如果不能满足满足题意就输出-1
     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<math.h>
     5 #include<algorithm>
     6 
     7 using namespace std;
     8 
     9 #define N 110
    10 #define INF 0x3f3f3f3f
    11 double dist[N][N];
    12 
    13 struct node
    14 {
    15     double x, y;
    16 }P[N];
    17 
    18 double distan(int i, int j)
    19 {
    20     double ans;
    21     ans = sqrt((P[i].x-P[j].x)*(P[i].x-P[j].x)+(P[i].y-P[j].y)*(P[i].y-P[j].y));
    22     return ans;
    23 }
    24 
    25 int main()
    26 {
    27     int t, m, n;
    28     scanf("%d", &t);
    29     while(t--)
    30     {
    31         scanf("%d%d", &m, &n);
    32         for(int i = 0; i < m; i++)
    33             scanf("%lf%lf", &P[i].x, &P[i].y);
    34         for(int i = 0; i < m; i++)
    35         {
    36             for(int j = i; j < m; j++)
    37             {
    38                 dist[i][j] = distan(i, j);
    39                 dist[j][i] = dist[i][j];
    40             }
    41             sort(dist[i], dist[i]+m);
    42         }
    43 
    44         int Min = INF;
    45         for(int i = 0; i < m; i++)
    46         {
    47             int v = dist[i][n-1]+1;   // 找距离为第n远的点……向上取整
    48             if(m == n || v < dist[i][n])   // 如果满足题意,就取最小值
    49                 Min = min(Min, v);
    50         }
    51         if(Min == INF)
    52             printf("-1
    ");
    53         else
    54             printf("%d
    ", Min);
    55     }
    56     return 0;
    57 }
  • 相关阅读:
    CSS从大图片上截取小图标的操作以及三角形的画法
    CSS3样式问题
    spilt()的用法
    如何测试一个网站
    在C/C++中static有什么用途
    对集成测试中自顶向下集成和自底向上集成两个策略的理解
    缺陷记录应包含的内容?
    主键、外键的作用,索引的优点与不足
    什么是兼容性测试
    测试用例的作用
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4831308.html
Copyright © 2011-2022 走看看