HDU 3622 bomb game (2-Sat)

Source: Internet
Author: User
HDU 3622 bomb game

Question Link

Ask for a maximum radius so that you can select one of the vertices in each Binary Group.

Train of Thought: Obviously the binary radius, then 2-sat to determine

Code:

#include <cstdio>#include <cstring>#include <cstdlib>#include <vector>#include <cmath>#include <algorithm>using namespace std;const int MAXNODE = 105;struct TwoSet {int n;vector<int> g[MAXNODE * 2];bool mark[MAXNODE * 2];int S[MAXNODE * 2], sn;void init(int tot) {n = tot * 2;for (int i = 0; i < n; i += 2) {g[i].clear();g[i^1].clear();}memset(mark, false, sizeof(mark));}void add_Edge(int u, int uval, int v, int vval) {u = u * 2 + uval;v = v * 2 + vval;g[u^1].push_back(v);g[v^1].push_back(u);}void delete_Edge(int u, int uval, int v, int vval) {u = u * 2 + uval;v = v * 2 + vval;g[u^1].pop_back();g[v^1].pop_back();}bool dfs(int u) {if (mark[u^1]) return false;if (mark[u]) return true;mark[u] = true;S[sn++] = u;for (int i = 0; i < g[u].size(); i++) {int v = g[u][i];if (!dfs(v)) return false;}return true;}bool solve() {for (int i = 0; i < n; i += 2) {if (!mark[i] && !mark[i + 1]) {sn = 0;if (!dfs(i)){for (int j = 0; j < sn; j++)mark[S[j]] = false;sn = 0;if (!dfs(i + 1)) return false;}}}return true;}} gao;const int N = 105;int n;struct Point {double x, y;void read() {scanf("%lf%lf", &x, &y);}} p[N][2];inline double dis(Point a, Point b) {double dx = a.x - b.x;double dy = a.y - b.y;return sqrt(dx * dx + dy * dy);}inline bool xj(Point a, Point b, double r) {if (dis(a, b) > 2 * r) return false;return true;}bool judge(double r) {gao.init(n);for (int i = 0; i < n; i++) {for (int j = i + 1; j < n; j++) {for (int x = 0; x < 2; x++) {for (int y = 0; y < 2; y++) {if (xj(p[i][x], p[j][y], r))gao.add_Edge(i, x, j , y);}}}}return gao.solve();}int main() {while (~scanf("%d", &n)) {for (int i = 0; i < n; i++)for (int j = 0; j < 2; j++)p[i][j].read();double l = 0, r = 1e5;for (int i = 0; i < 30; i++) {double mid = (l + r) / 2;if (judge(mid)) l = mid;else r = mid;}printf("%.2lf\n", l);}return 0;}


HDU 3622 bomb game (2-Sat)

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.