赛区网络赛"/>
hihoCoder 1227 The Cats' Feeding Spots 2015北京赛区网络赛
题意:t组测试数据
有n个点,先要求以其中的一个点为圆心画圆将m个点包围起来。求半径最小是多少,点不能在圆上。(坐标可以为小数)
分析:水题,由于数据比较小,直接枚举以每一个点为圆心的情况就可以了。注意半径要为整数。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <string>
#include <cmath>using namespace std;struct node
{double x,y;
}A[105];double a[105][105];
bool cmp(node a,node b)
{if(a.x==b.x)return a.y<b.y;return a.x<b.x;
}int main()
{int t,m,n;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);for(int i = 0 ; i < n ; i++){scanf("%lf%lf",&A[i].x,&A[i].y);}sort(A,A+n,cmp);for(int i = 0 ; i < n ; i++){for(int j = 0 ; j < n ; j++){if(i==j)a[i][j]=0;else a[i][j]=a[j][i]=sqrt((A[i].x-A[j].x)*(A[i].x-A[j].x)+(A[i].y-A[j].y)*(A[i].y-A[j].y));//cout<<a[i][j]<<endl;}}int num = 1000005;int ans = 0;int b,c;for(int i = 0 ; i < n ; i++){sort(a[i],a[i]+n);
// for(int j = 0 ; j < n ; j++)
// {
// cout<<a[i][j]<<" ";
// }
// cout<<endl;b = a[i][m-1];if(m!=n&&b+1>=a[i][m])c=-1;else{ans=1;c=b+1;}if(c!=-1&&c<=num)num=c;}if(ans==0)printf("-1\n");else printf("%d\n",num);}return 0;
}
更多推荐
hihoCoder 1227 The Cats' Feeding Spots 2015北京赛区网络赛
发布评论