1001 The Cats' Feeding Spots (2015年北京赛区网络赛A题)

编程入门 行业动态 更新时间:2024-10-05 21:20:37

1001 The Cats' Feeding Spots (2015年北京<a href=https://www.elefans.com/category/jswz/34/1758640.html style=赛区网络赛A题)"/>

1001 The Cats' Feeding Spots (2015年北京赛区网络赛A题)

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);}
}



更多推荐

1001 The Cats' Feeding Spots (2015年北京赛区网络赛A题)

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

发布评论

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

>www.elefans.com

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