hiho1227--The Cats' Feeding Spots
来源:互联网 发布:linux 修改目录结构 编辑:程序博客网 时间:2024/04/30 12:28
题目大意:给出M个喂食点,现在我们只能保留N个喂食点。以任意一个喂食点为圆心,任意半径作圆,在圆以内的点都可以留下,但是不能在圆上的出现点,因为管理者不好划分?求最小半径
分析:2015北京网赛签到题?直接暴力,枚举半径,然后枚举每个点为圆心时的情况,记录圆内的点以及圆上的点。
代码:
#include <cstdio>#include <cmath>#include <algorithm>using namespace std;#define eps 1e-7int T, m, n;int minr;struct P{ double x, y;}p[111];int main() { scanf("%d", &T); while(T--) { scanf("%d%d", &m, &n); for(int i = 0; i < m; i++) { scanf("%lf%lf", &p[i].x, &p[i].y); } minr = 1 << 30; for(int k = 1; k <= 1000; k++) { for(int i = 0; i < m; i++){ int cnt1 = 1, cnt2 = 0, flag = 0; for(int j = 0; j < m; j++) { if(i != j) { //这里千万不要再写一个求距离的函数,而是直接在求,不然TLE,亲测 double d = 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)); if(fabs(k*1.0-d) < eps) cnt2++; if(d < k*1.0) cnt1++; if(cnt2 > 0 || cnt1 > n) { flag = 1; break; } } } if(!flag && cnt1 == n && k < minr) minr = k; } } if(minr == 1 << 30) minr = -1; printf("%d\n", minr); } return 0;}
0 0
- hiho1227--The Cats' Feeding Spots
- 【HIHOCODER】The Cats' Feeding Spots
- hihoCoder1227 The Cats' Feeding Spots 二分
- hihoCoder #1227 : The Cats' Feeding Spots
- hihoCoder 1227 The Cats' Feeding Spots(水)
- hihoCoder 1227 The Cats' Feeding Spots
- hihoCoder1227 The Cats' Feeding Spots【暴力】
- hihocoder #1227 : The Cats' Feeding Spots(枚举)
- 北京赛区(2015)网络赛The Cats' Feeding Spots
- 1001 The Cats' Feeding Spots (2015年北京赛区网络赛A题)
- hihoCoder 1227 The Cats' Feeding Spots 2015北京赛区网络赛
- hihocoder #1227 : The Cats' Feeding Spots 北京赛区(2015)网络赛 (暴力枚举)
- hihoCoder 1227 The Cats' Feeding Spots(暴力)——ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛
- hihoCoder 1227 The Cats' Feeding Spots && ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛
- spoj 1418 The Cats and the Mouse
- poj 2761 feeding the dog (splay树 模板)
- 414. The leopard cannot change its spots. 本性难易
- feeding time
- PAT(甲级)1103
- 三步完成ssh免密码登录
- 18.Android 颜色工具类ColorUtil
- java判断字符串是否为空的方法总结
- 梯度下降法的简单理解
- hiho1227--The Cats' Feeding Spots
- MySQL中两个DateTime字段相减
- cc
- cvcv
- hiho一下第六十五周HighWay--也属于动态规划吧
- 关于团队建设和个人成长
- glPushMatrix()和glPopMatrix()的作用
- c/c++ 基本数据类型长度
- Python自然语言处理(一)--利用NLTK自带方法完成NLP基本任务