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 ;
}

The Cats' Feeding Spots的更多相关文章

  1. 2015北京网络赛 A题 The Cats' Feeding Spots 暴力

    The Cats' Feeding Spots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acm ...

  2. 2015北京网络赛A题The Cats' Feeding Spots

    题意:给你一百个点,找个以这些点为中心的最小的圆,使得这个圆恰好包含了n个点,而且这个圆的边界上并没有点 解题思路:暴力枚举每个点,求出每个点到其他点的距离,取第n大的点,判断一下. #include ...

  3. Cats(4)- 叠加Free程序运算结果,Stacking monadic result types

    在前面的几篇关于Free编程的讨论示范中我们均使用了基础类型的运算结果.但在实际应用中因为需要考虑运算中出现异常的情况,常常会需要到更高阶复杂的运算结果类型如Option.Xor等.因为Monad无法 ...

  4. Cats(3)- freeK-Free编程更轻松,Free programming with freeK

    在上一节我们讨论了通过Coproduct来实现DSL组合:用一些功能简单的基础DSL组合成符合大型多复杂功能应用的DSL.但是我们发现:cats在处理多层递归Coproduct结构时会出现编译问题.再 ...

  5. Cats(2)- Free语法组合,Coproduct-ADT composition

    上篇我们介绍了Free类型可以作为一种嵌入式编程语言DSL在函数式编程中对某种特定功能需求进行描述.一个完整的应用可能会涉及多样的关联功能,但如果我们为每个应用都设计一套DSL的话,那么在我们的函数式 ...

  6. Cats(1)- 从Free开始,Free cats

    cats是scala的一个新的函数式编程工具库,其设计原理基本继承了scalaz:大家都是haskell typeclass的scala版实现.当然,cats在scalaz的基础上从实现细节.库组织结 ...

  7. 矩阵快速幂 POJ 3735 Training little cats

    题目传送门 /* 题意:k次操作,g:i猫+1, e:i猫eat,s:swap 矩阵快速幂:写个转置矩阵,将k次操作写在第0行,定义A = {1,0, 0, 0...}除了第一个外其他是猫的初始值 自 ...

  8. [POJ 3735] Training little cats (结构矩阵、矩阵高速功率)

    Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9613   Accepted: 2 ...

  9. (中等) CF 311B Cats Transport,斜率优化DP。

    Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight r ...

随机推荐

  1. delphi 函数isiconic 函数 判断窗口是否最小化

    http://blog.sina.com.cn/s/blog_66357ab901012t2h.html delphi 函数isiconic 函数 判断窗口是否最小化 (2012-05-26 22:0 ...

  2. 双系统(win10+ubuntu)卸载Ubuntu系统

    之前装的双系统,Win10 和Ubuntu ,系统引导使用的是Ubuntu的Grup的引导, 直接删除Ubuntu会导致引导丢失,会很麻烦,win10直接会挂掉,后期恢复需要重建引导 安全删除思路,先 ...

  3. 安全测试工具之AppScan(Application)

    AppScan是一款Web应用安全测试工具,也是唯一一个在所有级别应用上提供安全纠正任务的工具.AppScan扫描Web应用的基础架构,进行安全漏洞测试并提供可行的报告和建议.AppScan的扫描能力 ...

  4. 【GTS】关于GtsTetheringTestCases模块的几个失败项

    GTS---关于GtsTetheringTestCases模块的几个失败项 1.run gts -m GtsTetheringTestCases -t com.google.android.tethe ...

  5. CSP2019 —— 今年欢笑复明年,不知退役在眼前

    关于2019CSP-J/-S的一些体会 又是一年退役季,想起在群里看到大佬的一句诗,感慨万千. 今年欢笑复明年,不知退役在眼前 于是便心生文意,随便写点东西来给自己康康. 先说说这次的成绩吧.大家应该 ...

  6. vue中如何实时修改输入的值

    vue中如何实时修改输入的值 经常看到需要对用户输入的值进行实时修改,有时是需要修改为指定的展示内容,有时候是用来校验,禁止用户输入非法数据,总之是一个常见的需求吧,只是自己一直没有特意去关注.思来想 ...

  7. Hystrix (容错,回退,降级,缓存)

    Hystrix熔断机制就像家里的保险丝一样,若同时使用高功率的电器,就会烧坏电路,这时候保险丝自动断开就有效的保护了电路.而我们程序中也同样是这样.例如若此时数据库压力太大速度很慢,此时还有不断的请求 ...

  8. C# 判断文件夹与文件是否存在

    //在上传文件时经常要判断文件夹是否存在,如果存在就上传文件,否则新建文件夹再上传文件 判断语句为 if (System.IO.Directory.Exists(Server.MapPath(&quo ...

  9. Linux awk抓取IP的两种方式

    ip addr show ens33 | awk -F "[ /]+" '/inet /{print $3}' 或 ifconfig ens33 | awk -F "[ ...

  10. JavaScript基础3——使用Button提交表单

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...