HDU 4173 Party location (computational geometry, enumeration)

Source: Internet
Author: User

HDU 4173

Test instructions: Known n (n<=200) position of the contestant's residence coordinates, now invite as many players as possible to participate in a party, and each player for more than 2.5Km from the house is not to go to the party, for the maximum number of players can go to participate.

Ideas:

Consider the possible location of the party, and to invite as many players as possible, just consider where the party is located at the midpoint of a two-bit residence line or the location of a contestant's residence, as this is where the largest number of participants is likely to be located.

If the maximum number of participants can be obtained from other locations, then the midpoint or the contestant's residence will be available. Ok~, try to draw.

So, as long as we enumerate all the midpoint and the position of the contestant's residence, we can get the number of the party contestants, and the maximum value is the answer.

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 = +5;pair<do Uble,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;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4173 Party location (computational geometry, enumeration)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.