原題連接:http://hihocoder.com/problemset/problem/1227ios
題意:在m個點中找一個點爲圓心, 求可以精確包括n個點的最小的半徑,要求半徑爲整數。this
分析:一開始沒看清題意,覺得是憑空的一個圓,後來才發現是m個點中的某一個,感受本身有點sb。。spa
而後想到直接暴力,100*100,暴力每一個點,求每一個點到它的距離,排個序求出第n個,向上取整,若是觸碰到外圍的一個點就表示不行。code
須要注意的是,若是m==n就不須要額外判外圍的點,並且當m>n的時候,應該輸出-1.blog
代碼:string
1 #include <set> 2 #include <map> 3 #include <list> 4 #include <cmath> 5 #include <queue> 6 #include <vector> 7 #include <bitset> 8 #include <string> 9 #include <cctype> 10 #include <cstdio> 11 #include <cstring> 12 #include <cstdlib> 13 #include <iostream> 14 #include <algorithm> 15 16 using namespace std; 17 18 typedef long long ll; 19 typedef unsigned long long ull; 20 #define inf (0x3f3f3f3f) 21 #define lnf (0x3f3f3f3f3f3f3f3f) 22 #define eps (1e-8) 23 int sgn(double a) {return a < -eps ? -1 : a < eps ? 0 : 1;} 24 25 //-------------------------- 26 27 28 int t; 29 int m, n; 30 31 class point { 32 public: 33 double x, y; 34 point(double x, double y) { 35 this->x = x; 36 this->y = y; 37 } 38 39 }; 40 41 vector<point> p; 42 43 double dis(point p1, point p2) { 44 return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); 45 } 46 47 void solve() { 48 scanf("%d", &t); 49 while (t--) { 50 p.clear(); 51 scanf("%d%d", &m, &n); 52 for (int i = 0; i < m; i++) { 53 double x, y; 54 scanf("%lf%lf", &x, &y); 55 p.push_back(point(x, y)); 56 } 57 int ans = inf; 58 for (int i = 0; i < m; i++) { 59 double res; 60 double ds[110]; 61 for (int j = 0; j < m; j++) { 62 ds[j] = dis(p[i], p[j]); 63 } 64 sort(ds, ds + m); 65 res = ceil(ds[n - 1]); 66 if (res == ds[n - 1])res += 1; 67 if (m > n && res >= ds[n])continue; 68 ans = min(ans, (int)res); 69 } 70 if (ans == inf || n > m) { 71 puts("-1"); 72 } else { 73 printf("%d\n", ans); 74 } 75 } 76 77 } 78 79 int main() { 80 81 #ifndef ONLINE_JUDGE 82 freopen("1.in", "r", stdin); 83 //freopen("1.out", "w", stdout); 84 #endif 85 //iostream::sync_with_stdio(false); 86 solve(); 87 return 0; 88 }
感悟:這種坑精度的題感受本身有點懵逼,要多坑一坑。。it