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

来源:互联网 发布:淘宝详情页装修 编辑:程序博客网 时间:2024/06/06 03:44

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


0 0
原创粉丝点击