1001 The Cats' Feeding Spots (2015年北京赛区网络赛A题)
来源:互联网 发布:罗技淘宝 编辑:程序博客网 时间:2024/04/30 13:04
1.题目描述:点击打开链接
2.解题思路:本题需要分三种情况讨论:(1) n<m (2) n==m (3) n>m。首先枚举圆心,然后计算其他点相对于该圆心的距离,排序后根据情况来讨论即可。
3.代码:
#include<iostream>#include<algorithm>#include<cassert>#include<string>#include<sstream>#include<set>#include<bitset>#include<vector>#include<stack>#include<map>#include<queue>#include<deque>#include<cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<ctime>#include<cctype>#include<complex>#include<functional>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define me(s) memset(s,0,sizeof(s))#define rep(i,n) for(int i=0;i<(n);i++)typedef long long ll;typedef unsigned int uint;typedef unsigned long long ull;typedef pair <ll, ll> P;const int N=100+10;const int INF=1000000000;double x[N],y[N];const double eps=1e-10;int dcmp(double x){ if(fabs(x)<eps)return 0; return x<0?-1:1;}double dist[N];double dis(double dx,double dy){ return sqrt(dx*dx+dy*dy);}int n,m;int calc(int s){ me(dist); int idx=1; for(int i=0;i<m;i++) if(i!=s) dist[idx++]=dis(x[i]-x[s],y[i]-y[s]); sort(dist,dist+idx); if(n<m) { int upp=ceil(dist[n-1]); if(dcmp((double)upp-dist[n-1])==0) { if(dcmp(dist[n]-(double)upp-1.0)<=0)return INF; else return upp+1; } else { if(dcmp(dist[n]-(double)upp)<=0)return INF; else return upp; } } else if(n==m) { int upp=ceil(dist[n-1]); if(dcmp((double)upp-dist[n-1])==0)return upp+1; else return upp; } else return INF;}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d%d",&m,&n); for(int i=0;i<m;i++) scanf("%lf%lf",&x[i],&y[i]); int ans=INF; for(int i=0;i<m;i++) { ans=min(ans,calc(i)); } if(ans==INF)puts("-1"); else printf("%d\n",ans); }}
0 0
- 1001 The Cats' Feeding Spots (2015年北京赛区网络赛A题)
- 北京赛区(2015)网络赛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)网络赛
- 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(枚举)
- 北京赛区(2016)网络赛 A题 The Book List
- Cats and Fish2017北京赛区网络同步赛
- 【2016-北京赛区网络赛-A】水题(The Book List,hihocoder 1383)
- 2015北京赛区网络赛模拟题
- Git 常用命令整理
- Revit二次开发之入门
- pageEncoding和contentType
- sublime text2使用总结
- Android——百度地图开发、添加覆盖物、地理编码和反地理编码、以及覆盖物之间的连线
- 1001 The Cats' Feeding Spots (2015年北京赛区网络赛A题)
- C++Primer第五版 11.1节练习
- Pthread多线程超时取消
- c/c++ coroutine
- List和Vector的简单用法(MFC)
- Nbportnmap 多线程端口banner收集工具
- 初步了解spring的aop
- Java中的instanceof关键字
- 利用MemoryAnalyzer进行OutOfMemoryError的诊断分析