HDU 4173 Party Location(计算几何,枚举)

HDU 4173

题意:已知n(n<=200)位參赛选手的住所坐标。现要邀请尽可能多的选手来參加一个party,而每一个选手对于离住所超过2.5Km的party一律不去,求最多能够有多少个选手去參加party。

思路:

最好还是先考虑party可能的位置,要尽可能多的邀请到选手參加,则仅仅需考虑party所在位置在某两位住所连线的中点上或某选手住所所在位置,由于这是最大參加party选手数非常有可能在的位置。

若其它位置能得到最大參加选手数。那么中点或选手住所也一定可得到。

//反证法可得。试着画画就ok~

那么,仅仅要我们枚举全部中点与选手住所的位置。所能得到的可參加party选手数,取其最大值即是答案。

AC code:


/*
* @author Novicer
* language : C++/C
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;

const int maxn = 200 +5;
pair<double,double>con[maxn];

int main(){
//	freopen("input.txt","r",stdin);
	int n;
	while(cin >> n){
		for(int i = 1 ; i <= n ; i++) scanf("%lf%lf",&con[i].first,&con[i].second);
		int ans = 0;
		for(int i = 1 ; i <= n ; i++){
//			cout << con[i].first << " " << con[i].second << endl;
			for(int j = 1 ; j <= n ; j++){
				pair<double,double> t;
				t.first = (con[i].first + con[j].first) / 2.0;
				t.second = (con[i].second + con[j].second) / 2.0;
//				cout << t.first << " " << t.second << endl;
				int cnt = 0;
				for(int k = 1 ; k <= n ; k++){
					double dis = pow(t.first - con[k].first,2) + pow(t.second - con[k].second,2);
//					cout << dis << endl;
					if(dis <= 6.25 + eps) cnt++;
				}
				ans = max(ans , cnt);
			}
		}
		cout << ans << endl;
	}
	return 0;
}



【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/llguanli/p/8401314.html