赛区网络赛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题)
发布评论