{"id":106,"date":"2010-09-09T10:24:10","date_gmt":"2010-09-09T02:24:10","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=106"},"modified":"2012-03-03T08:24:27","modified_gmt":"2012-03-03T00:24:27","slug":"poj-2728-desert-king","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/poj-2728-desert-king\/","title":{"rendered":"POJ 2728. Desert King"},"content":{"rendered":"<h3>Brief description :<\/h3>\n<p>\u73b0\u5728\u5728n\u4e2a\u6751\u5e84\u7684\u5730\u56fe\u5750\u6807\u548c\u9ad8\u5ea6\uff0c\u8981\u5728\u4ed6\u4eec\u4e4b\u95f4\u94fa\u8bbe\u4e00\u4e9b\u6c34\u7ba1, \u4e3a\u4e86\u8282\u7701\u9884\u7b97\uff0c\u53ea\u8981\u6c42\u6784\u6210\u6700\u5c0f\u751f\u6210\u6811\u5373\u53ef\uff0c\u53e6\u5916\u56fd\u738b\u5e0c\u671b\u6c34\u7ba1\u7684\u5761\u5ea6\u4e0d\u4f1a\u592a\u9661\uff0c\u6700\u5c0f\u5316\u9ad8\u5ea6\u5dee\u4e0e\u957f\u5ea6\u7684\u6bd4\u503c\u3002<br \/>\n<!--more--><\/p>\n<h3>Analyse :<\/h3>\n<p>\u6050\u6015\u8fd9\u4e2a\u5c31\u662f\u7ecf\u5178\u7684\u6700\u4f18\u6bd4\u7387\u751f\u6210\u6811\u3002\u3002\u3002\uff03<\/p>\n<pre lang=\"cpp\">\r\n\/*\r\n    Author  : xiaodao\r\n    Problem : POJ 2728. Desert King\r\n    Status  : Accepted\r\n    Last Modify : GMT +8. Sept 9th 15:43.\r\n    Tags : \u6700\u4f18\u6bd4\u7387\u751f\u6210\u6811\r\n\r\n*\/\r\n#include <iostream>\r\n#include <cstdio>\r\n#include <cmath>\r\nusing namespace std;\r\nconst double EPS = 1e-6, INF = 1e9;\r\nconst int N = 1000;\r\nstruct po{\r\n    double x, y; int h;\r\n    double k; bool c;\r\n} P[N];\r\nint n;\r\ndouble ans;\r\n\r\n\r\ninline int cost(int a, int b){\r\n    return abs(P[a].h-P[b].h);\r\n}\r\n\r\ninline double dist(int a, int b){\r\n    return sqrt((P[a].x-P[b].x)*(P[a].x-P[b].x) + (P[a].y-P[b].y)*(P[a].y-P[b].y));\r\n}\r\n\r\n\r\ninline int Extract(){\r\n    int i = 0, h;\r\n    while (P[i].c) i++; h = i;\r\n    for (i++;i<n;i++){\r\n        if (P[i].c) continue;\r\n        if (P[i].k < P[h].k) h = i;\r\n    }\r\n    P[h].c = true;\r\n    return h;\r\n}\r\n\r\ninline void Relax(int v, double w){\r\n    P[v].k = min(P[v].k, w);\r\n}\r\n\r\n\r\n\r\ndouble f(double x){\r\n    double mst = 0;\r\n    for (int i=0;i<n;i++)\r\n        P[i].k = INF, P[i].c = false;\r\n    P[0].k = 0;\r\n\r\n    int u;\r\n    for (int i=0;i<n;i++){\r\n        u = Extract();\r\n        mst += P[u].k;\r\n        for (int v=1;v<n;v++){\r\n            if (P[v].c) continue;\r\n            Relax(v, cost(u, v) - x * dist(u, v));\r\n        }\r\n    }\r\n    return mst;\r\n}\r\n\r\n\r\n\r\nvoid solve(){\r\n    double l, r, m;\r\n    l = INF; r = 0;\r\n    for (int i=0;i<n;i++)\r\n        for (int j=0;j<n;j++){\r\n            if (i==j) continue;\r\n            double t = cost(i, j)\/dist(i, j);\r\n            l = min(l, t), r = max(r, t);\r\n        }\r\n    l -= EPS; r += EPS;\r\n\r\n    l = 0 ; r = 100;\r\n\r\n    while (l+EPS<r){\r\n        m = (l+r) \/ 2;\r\n        if (f(m) > 0) l = m;\r\n        else r = m;\r\n    }\r\n    ans = l;\r\n}\r\n\r\nvoid init(){\r\n    for (int i=0;i<n;i++)\r\n        scanf(\"%lf%lf%d\", &#038;P[i].x, &#038;P[i].y, &#038;P[i].h);\r\n}\r\n\r\nint main(){\r\n    while (scanf(\"%d\", &#038;n)==1 &#038;&#038; n!=0){\r\n        init(); solve();\r\n        printf(\"%.3lf\\n\", ans);\r\n    }\r\n}\r\n<\/pre>\n<h3>External link :<\/h3>\n<p>http:\/\/acm.pku.edu.cn\/JudgeOnline\/problem?id=2728<br \/>\nhttp:\/\/hi.baidu.com\/%8E%E1%D0%B3\/blog\/item\/199c38d4e614762207088bf0.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description : \u73b0\u5728\u5728n\u4e2a\u6751\u5e84\u7684\u5730\u56fe\u5750\u6807\u548c\u9ad8\u5ea6\uff0c\u8981\u5728\u4ed6\u4eec\u4e4b\u95f4\u94fa\u8bbe\u4e00\u4e9b\u6c34\u7ba1, \u4e3a\u4e86\u8282\u7701\u9884\u7b97\uff0c\u53ea\u8981\u6c42\u6784\u6210\u6700\u5c0f\u751f\u6210\u6811\u5373\u53ef\uff0c\u53e6\u5916\u56fd\u738b\u5e0c\u671b\u6c34\u7ba1\u7684\u5761\u5ea6\u4e0d\u4f1a\u592a\u9661\uff0c\u6700\u5c0f\u5316\u9ad8\u5ea6\u5dee\u4e0e\u957f\u5ea6\u7684\u6bd4\u503c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-106","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-1I","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=106"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/106\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}