hihoCoder 1227 The Cats' Feeding Spots
来源:互联网 发布:python 微信提醒 编辑:程序博客网 时间:2024/04/30 11:58
The 2015 ACM-ICPC Asia Beijing First Round Online Programming Contest
题意:找出以所给的点为圆心的圆,使得它包含n个点(包括圆心),输出这种圆半径最小值,半径必须是正整数。点不能落在圆上,只能在圆内。
由于m,n的值都很小,所以可以暴力过,计算出每个点到其他点的距离,然后枚举每个点,把它到其他点的距离放进优先队列,再从队列中取足n-1个点(自身已经算1个),注意当把半径+1的时候,考虑会不会把更多的点给包含进来,求出符合要求的最小半径即可。
#include <stdio.h>#include <queue>#include <math.h>#include <string.h>using namespace std;struct node{ double x, y; double dis[105];}spot[105];int main(){ int t, i, j, m, n, p, minR, tmp; double maxn, minn; bool flag; scanf("%d", &t); while(t--) { scanf("%d %d", &m, &n); for(i = 0;i < m;i++) scanf("%lf %lf", &spot[i].x, &spot[i].y); if(m < n){ printf("-1\n"); continue; } for(i = 0;i < m;i++) { p = 0; for(j = 0;j < m;j++) if(i != j) spot[i].dis[p++] = sqrt((spot[i].x-spot[j].x)*(spot[i].x-spot[j].x) + (spot[i].y-spot[j].y)*(spot[i].y-spot[j].y)); } minR = 1005; flag = 0; for(i = 0;i < m;i++) { priority_queue<double, vector<double>, greater<double> > q; for(j = 0;j < m - 1;j++) q.push(spot[i].dis[j]); j = 1; maxn = 0; while(j < n) { maxn = q.top(); q.pop(); j++; } minn = 1005; if(!q.empty()) minn = q.top(); tmp = maxn; tmp++; if(tmp >= minn) continue; flag = 1; minR = tmp<minR?tmp:minR; } if(!flag) printf("-1\n"); else printf("%d\n", minR); } return 0;}
0 0
- hihoCoder #1227 : The Cats' Feeding Spots
- hihoCoder 1227 The Cats' Feeding Spots(水)
- hihoCoder 1227 The Cats' Feeding Spots
- hihocoder #1227 : The Cats' Feeding Spots(枚举)
- 【HIHOCODER】The Cats' Feeding Spots
- hiho1227--The Cats' Feeding Spots
- 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)网络赛
- hihoCoder1227 The Cats' Feeding Spots 二分
- hihoCoder1227 The Cats' Feeding Spots【暴力】
- 北京赛区(2015)网络赛The Cats' Feeding Spots
- 1001 The Cats' Feeding Spots (2015年北京赛区网络赛A题)
- Cats and Fish HihoCoder
- hihocoder 1631 Cats and Fish
- Hihocoder #1631 : Cats and Fish 模拟
- Cats and Fish 2017ACM-ICPC北京赛区/hihoCoder 1631
- 在网页中添加QQ客服聊天
- JPA 基本注解
- TableView and ScrollView
- 两年大学的一个小小总结
- Parameter 'p_REMARK': No size set for variable length data type: String.
- hihoCoder 1227 The Cats' Feeding Spots
- 什么是防御性编程,如何进行防御性编程
- 图像处理、图像分析、图像理解 范畴区分
- VC6中XML解析相关笔记
- 七个对我最重要的职业建议(译文)
- 关于 as! 操作符
- Linearlayout如何右对齐
- xp使时间无法与服务器同步的方法
- org.eclipse.swt.SWTError: No more handles, eclipse插件开发错误问题