码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-07-25 23:01:25      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:acm   枚举   计算几何   

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



版权声明:本文为博主原创文章,未经博主允许不得转载。

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

标签:acm   枚举   计算几何   

原文地址:http://blog.csdn.net/qq_15714857/article/details/47060439

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!