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

EmacsNormalVim

题意:大学生照看好多猫,设置了几个安置点,现在需要以任意一个安置点为圆心画圆,在圆内有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\n");
53         else
54             printf("%d\n", Min);
55     }
56     return 0;
57 }

The Cats' Feeding Spots

时间: 2024-10-12 18:11:06

The Cats' Feeding Spots的相关文章

(暴力+精度)hihocoder - 1227 The Cats&#39; Feeding Spots

原题链接:http://hihocoder.com/problemset/problem/1227 题意:在m个点中找一个点为圆心, 求能够精确包括n个点的最小的半径,要求半径为整数. 分析:一开始没看清题意,以为是凭空的一个圆,后来才发现是m个点中的某一个,感觉自己有点sb.. 然后想到直接暴力,100*100,暴力每个点,求每个点到它的距离,排个序求出第n个,向上取整,如果触碰到外围的一个点就表示不行. 需要注意的是,如果m==n就不需要额外判外围的点,而且当m>n的时候,应该输出-1. 代

2015北京网络赛A题The Cats&#39; Feeding Spots

题意:给你一百个点,找个以这些点为中心的最小的圆,使得这个圆恰好包含了n个点,而且这个圆的边界上并没有点 解题思路:暴力枚举每个点,求出每个点到其他点的距离,取第n大的点,判断一下. 1 #include<cstdio> 2 #include<cmath> 3 #include<algorithm> 4 #include<iostream> 5 #include<memory.h> 6 using namespace std; 7 const i

hihocode_1227——ceil——The Cats&#39; Feeding Spots

http://hihocoder.com/problemset/problem/1227 /************************************************ * Author :Powatr * Created Time :2015/9/21 14:46:41 * File Name :A.cpp ************************************************/ #include <cstdio> #include <al

2015 ACM-ICPC 北京赛区 网络赛 部分 题解

由于博主水平及智商不足,所以暂时只能放出下列的题目的题解. A B D F G H 需要其他题解请自行前往 http://talk.icpc-camp.org/ 题目地址:hihocoder 1227-1236 A.  The Cats' Feeding Spots 题意:给出M个点,求以其中一个点为圆心,最小半径的圆,使得这个圆里恰好有N个点. (半径一定要是整数,且点不能恰好在圆上). 方法:暴力,稍微注意一下精度什么的就好了,1A. 1 #include <bits/stdc++.h>

2015 ACM/ICPC Asia Regional Beijing Online

A The Cats' Feeding Spots B Mission Impossible 6 模拟题.想法是用结构体数组做一个链表. 比赛的时候WA了.说一下几个注意点. 1.光标到头的时候不能再动了. 2.字符总数不能超过M,如果V操作溢出则不执行V操作(而不是粘贴部分). 3.复制的时候有左右方向. 4.复制状态下进行了除L/R/D以外的操作则停止复制.注意!!此时不更新剪贴板. 5.每次操作之后记得更新光标的位置. 6.每个Case初始化各种变量时,串与剪贴板清空. 反思:比赛的时候思

URAL 1617. Flat Spots(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1612 1617. Flat Spots Time limit: 0.5 second Memory limit: 64 MB Yekaterinburg has an extensive network of tram routes. Trams of more than ten routes go along some streets. It is clear that rails wear

(中等) 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 road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The fee

POJ3735 Training little cats DP,矩阵快速幂,稀疏矩阵优化

题目大意是,n只猫,有k个动作让它们去完成,并且重复m次,动作主要有三类gi,ei,s i j,分别代表第i只猫获得一个花生,第i只猫吃掉它自己所有的花生,第i只和第j只猫交换彼此的花生.k,n不超过100,m不超过1000,000,000,计算出最后每只猫还剩下多少个花生. 我们假设一个n维向量P,每个分量的值代表这n只猫所拥有的花生数,那么对于gi操作其实就是在第i维分量上加上1:对于ei,那就是在第i维分量上乘以0,说到这里,有木有感觉这很像3D坐标转化中的平移矩阵和缩放矩阵?没错,就是这

POJ 3735 Training little cats (矩阵快速幂)

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10593   Accepted: 2532 Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make t