The Cats' Feeding Spots
The Cats' Feeding Spots
描述
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
#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的更多相关文章
- 2015北京网络赛 A题 The Cats' Feeding Spots 暴力
The Cats' Feeding Spots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acm ...
- 2015北京网络赛A题The Cats' Feeding Spots
题意:给你一百个点,找个以这些点为中心的最小的圆,使得这个圆恰好包含了n个点,而且这个圆的边界上并没有点 解题思路:暴力枚举每个点,求出每个点到其他点的距离,取第n大的点,判断一下. #include ...
- Cats(4)- 叠加Free程序运算结果,Stacking monadic result types
在前面的几篇关于Free编程的讨论示范中我们均使用了基础类型的运算结果.但在实际应用中因为需要考虑运算中出现异常的情况,常常会需要到更高阶复杂的运算结果类型如Option.Xor等.因为Monad无法 ...
- Cats(3)- freeK-Free编程更轻松,Free programming with freeK
在上一节我们讨论了通过Coproduct来实现DSL组合:用一些功能简单的基础DSL组合成符合大型多复杂功能应用的DSL.但是我们发现:cats在处理多层递归Coproduct结构时会出现编译问题.再 ...
- Cats(2)- Free语法组合,Coproduct-ADT composition
上篇我们介绍了Free类型可以作为一种嵌入式编程语言DSL在函数式编程中对某种特定功能需求进行描述.一个完整的应用可能会涉及多样的关联功能,但如果我们为每个应用都设计一套DSL的话,那么在我们的函数式 ...
- Cats(1)- 从Free开始,Free cats
cats是scala的一个新的函数式编程工具库,其设计原理基本继承了scalaz:大家都是haskell typeclass的scala版实现.当然,cats在scalaz的基础上从实现细节.库组织结 ...
- 矩阵快速幂 POJ 3735 Training little cats
题目传送门 /* 题意:k次操作,g:i猫+1, e:i猫eat,s:swap 矩阵快速幂:写个转置矩阵,将k次操作写在第0行,定义A = {1,0, 0, 0...}除了第一个外其他是猫的初始值 自 ...
- [POJ 3735] Training little cats (结构矩阵、矩阵高速功率)
Training little cats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9613 Accepted: 2 ...
- (中等) 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 ...
随机推荐
- MVC 源码系列之控制器执行(二)
## 控制器的执行 上一节说道Controller中的ActionInvoker.InvokeAction public virtual bool InvokeAction(ControllerCon ...
- 获取当前进程当前runtime加载的appdomain
using System.Runtime.InteropServices; // Add the following as a COM reference - C:\WINDOWS\Microsoft ...
- PHP多图片上传 并检查 加水印 源码
参数说明:$max_file_size : 上传文件大小限制, 单位BYTE$destination_folder : 上传文件路径$watermark : 是否附加水印(1为加水印,其他为不加水印) ...
- UIAutomation元素识别软件
通过Python调用UIAutomation库来开发代码时,都会遇到需要识别元素的问题.笔者在这里推荐两款好用的软件:UISpy和Inspect. UISpy识别元素后,我们需要的属性有:ClassN ...
- oracle--ORA常见报错
常见错误地址 http://ora-12xyz.com/error/ora-01911 ORA-01034和ORA-27101的解决办法 出现ORA-01034和ORA-27101的原因是多方面的:主 ...
- oracle--多表联合查询sql92版
sql92学习 -查询员工姓名,工作,薪资,部门名称 sql的联合查询(多表查询) --1.sql92标准 ----笛卡尔积:一件事情的完成需要很多步骤,而不同的步骤有很多种方式,完成这件事情的所有方 ...
- 使用gitlab的webhook进行前端自动部署
gitlab有个功能叫webhook,比较适合前端代码的自动部署.其中的逻辑在 http://172.30.83.152:30080/help/user/project/integrations/w ...
- PTA第二题
#include<string.h> #include<stdio.h> #include<malloc.h> ]; ][]={"ling",& ...
- Arrays.asList使用指南和一些坑(转)
一.java.util.Arrays.asList() 的一般用法 List 是一种很有用的数据结构,如果需要将一个数组转换为 List 以便进行更丰富的操作的话,可以这么实现: String[] m ...
- python基础篇(完整版)
目录 计算机基础之编程和计算机组成 什么是编程语言 什么是编程 为什么要编程 编程语言的分类 机器语言(低级语言) 汇编语言 高级语言 计算机的五大组成 CPU(相当于人类的大脑) 多核CPU(多个大 ...