hihoCoder 1227 The Cats' Feeding Spots 2015北京赛区网络赛

编程入门 行业动态 更新时间:2024-10-10 12:23:10

hihoCoder 1227 The Cats' Feeding Spots 2015北京<a href=https://www.elefans.com/category/jswz/34/1758481.html style=赛区网络赛"/>

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北京赛区网络赛

本文发布于:2024-02-13 12:45:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1758640.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:赛区   北京   网络   Cats   hihoCoder

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!