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
 #include <iostream>
#include<cstdio>
#include<cstring>
#include<math.h>
#include<algorithm> using namespace std; #define N 110
#define INF 0x3f3f3f3f
double dist[N][N]; struct node
{
double x, y;
}P[N]; double distan(int i, int j)
{
double ans;
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));
return ans;
} int main()
{
int t, m, n;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &m, &n);
for(int i = ; i < m; i++)
scanf("%lf%lf", &P[i].x, &P[i].y);
for(int i = ; i < m; i++)
{
for(int j = i; j < m; j++)
{
dist[i][j] = distan(i, j);
dist[j][i] = dist[i][j];
}
sort(dist[i], dist[i]+m);
} int Min = INF;
for(int i = ; i < m; i++)
{
int v = dist[i][n-]+; // 找距离为第n远的点……向上取整
if(m == n || v < dist[i][n]) // 如果满足题意,就取最小值
Min = min(Min, v);
}
if(Min == INF)
printf("-1\n");
else
printf("%d\n", Min);
}
return ;
}

最新文章

  1. 异步编程系列第01章 Async异步编程简介
  2. DB监控-mysql监控
  3. 【CQOI2016纯净整合】BZOJ-4519~4524 (6/6)
  4. java-HashMap方法讲解
  5. Form文件夹开发步骤
  6. LTIB常用命令2
  7. 前端页面js与flash交互——js获取flash对象,并传递参数
  8. SQLServer错误代码解释
  9. 就谈个py 的装饰器 decorator
  10. Redis学习手册(事务)
  11. [转] 属性选择器.mark
  12. Android学习----打印日志Log
  13. C#三种方式实现序列化(转)
  14. C# 将XML格式字符串,写入数据集的表中 XML解析
  15. springMVC整合JAXB
  16. Atlassian - Confluence Security Advisory - 2019-03-20
  17. JS的document.images函数使用示例
  18. SpringCloud(一)浅谈SpringCloud
  19. Android学习笔记——关于onConfigurationChanged(转)
  20. C#反射——简单反射操作类的封装

热门文章

  1. AUTOGUI生成的一个简易文本编辑器
  2. Android Bitmap变迁与原理解析(4.x-8.x)
  3. Makefile之patsubst
  4. vue 常用插件,保存
  5. glibc升级,解决glib版本过低的问题
  6. Java基础/发起http和https请求
  7. 20191103 《Spring5高级编程》笔记-第4章
  8. c++中关于类的长度的猜想
  9. 不用找了,300 分钟帮你搞定 Spring Cloud!
  10. 【题解】Oh My Holy FFF