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 ...
随机推荐
- 类Runtime
Runtime类的概述和使用 Runtime类概述 每个Java应用程序都有一个Runtime类实例,使应用程序能够与其运行的环境相连接.可以通过getRuntime方法获取当前运行时. 应用程序不能 ...
- 抓取某高校附近共享单车位置,并使用web方式展示过去几天的位置变化
效果如图 使用了高德地图API:https://lbs.amap.com/api/javascript-api/example/marker/massmarks js代码如下: function Ma ...
- 【MM系列】SAP 主要模块及简介
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 主要模块及简介 前言部分 ...
- VUe.js 父组件向子组件中传值及方法
父组件向子组件中传值 1. Vue实例可以看做是大的组件,那么在其内部定义的私有组件与这个实例之间就出现了父子组件的对应关系. 2. 父子组件在默认的情况下,子组件是无妨访问到父组件中的数据的,所以 ...
- 关于Vue的理解以及与React框架的对比
1.Vue的理解 概念: Vue是一套用于构建用户界面的渐进式框架: Vue的核心库只关注视图层: 是一个数据驱动的MVVM框架: 特性: 确实轻量:体积比较小: 数据绑定简单.方便: 有一些简单的内 ...
- 分享一篇Linux系统使用Tomcat服务时交互式修改server.xml中端口号的shell脚本
#!/bin/bash echo -e '\n' echo "***********************************" port1=`grep -r "s ...
- [2019杭电多校第四场][hdu6623]Minimal Power of Prime
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6623 题目大意为求一个数的唯一分解的最小幂次.即120=23*31*51则答案为1. 因为数字太大不能 ...
- dp(电梯与楼梯)
http://codeforces.com/problemset/problem/1249/E E. By Elevator or Stairs? time limit per test 2 seco ...
- 一键生成APK
傻瓜式的生成APK网址:https://www.appbsl.com/ 第一步 第二步 第三步 第四步
- Bloxorz I (poj3322) (BFS)
[题目描述] It's a game about rolling a box to a specific position on a special plane. Precisely, the pla ...