{"id":147,"date":"2011-10-20T20:19:42","date_gmt":"2011-10-20T12:19:42","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=147"},"modified":"2012-03-03T23:10:20","modified_gmt":"2012-03-03T15:10:20","slug":"zoj-3546-advanture-of-xiaoxingxing","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/zoj-3546-advanture-of-xiaoxingxing\/","title":{"rendered":"ZOJ 3546. Advanture of Xiaoxingxing"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>\u7ffb\u7eb8\u76d2\u95ee\u9898\uff0c\u7ed9\u5b9a\u4e00\u4e2a N \u4e2a\u9876\u70b9\u7684\u7b80\u5355\u591a\u8fb9\u5f62\uff0c\u95ee\u6cbf\u7740 x \u8f74\u8fdb\u884c\u6eda\u52a8\uff0c\u89e6\u78b0 T \u70b9\u65f6\u7ffb\u6eda\u7684\u89d2\u5ea6\u3002<br \/>\n\u591a\u8fb9\u5f62\u7684\u9876\u70b9\u6309\u7167\u987a\u65f6\u9488\u6216\u9006\u65f6\u9488\u7ed9\u51fa\uff0c\u4e14\u7b2c\u4e00\u4e2a\u70b9\u662f\u6e90\u70b9\uff0cT \u70b9\u4e00\u5b9a\u5728\u8fd9\u4e2a\u591a\u8fb9\u5f62\u7684\u53f3\u8fb9\uff0c\u6240\u6709\u70b9\u7684 y \u8f74\u5750\u6807 >= 0\u3002<br \/>\n.. ( N <= 100 ).. .\n\n<!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>\u3002\u3002\u3002\u82b1\u4e86 5 \u4e2a\u5c0f\u65f6\u603b\u7b97 A \u6389\u4e86\u8fd9\u4e2a\u9898\u3002\u3002\u53ef\u89c1\u73b0\u573a\u8d5b\u7684\u65f6\u5019\u662f\u6839\u672c\u5199\u4e0d\u51fa\u6765\u7684\u3002\u3002<br \/>\n\u4e48\uff1f\u3002<\/p>\n<p>\u3002\u3002\u8fd9\u9898\u7684\u505a\u6cd5\u5e76\u4e0d\u662f\u5f88\u96be\u60f3\u3002\u3002\u5305\u62ec\u5148\u6c42\u51f8\u5305\u3001\u8ba1\u7b97\u65cb\u8f6c\u7528\u7684\u5916\u89d2\u3001\u8ba1\u7b97\u5468\u957f\u3002\u3002\u8fdb\u884c\u4e00\u6b21\u7b2c\u4e00\u6b21\u7ffb\u6eda\uff08\u53d6\u6a21\u3002\u3002\uff09\u3002\u3002<br \/>\n\u3002\u3002\u90fd\u662f\u53ef\u4ee5\u5199\u7684\u3002\u3002\u90a3\u4e48\u552f\u4e00\u7684\u96be\u70b9\u5373\u4f7f\u4e34\u8fd1\u7ed3\u675f\u4e4b\u65f6\u3002\u3002<\/p>\n<p>\u3002\u3002\u3002\u3002\u4f8b\u5b50\u3002\u3002<\/p>\n<p><a href=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/01.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"149\" data-permalink=\"https:\/\/www.shuizilong.com\/house\/archives\/zoj-3546-advanture-of-xiaoxingxing\/attachment\/0\/\" data-orig-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/01.png\" data-orig-size=\"452,322\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"0\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/01-300x213.png\" data-large-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/01.png\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/01.png\" alt=\"\" title=\"0\" width=\"452\" height=\"322\" class=\"aligncenter size-full wp-image-149\" srcset=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/01.png 452w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/01-300x213.png 300w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/01-421x300.png 421w\" sizes=\"auto, (max-width: 452px) 100vw, 452px\" \/><\/a><\/p>\n<p>\uff08\u5982\u56fe\u6240\u793a\uff0c\u3002\u3002\u3002\u76ee\u6807\u70b9\u5728\u201c\u6c99\u6f0f\u201d\u5f62\u72b6\u7684\u7b80\u5355\u591a\u8fb9\u5f62\u7684\u51f9\u89d2\u91cc\u9762\u3002\u3002<br \/>\n\u8fd9\u79cd\u60c5\u51b5\u4e0d\u4f1a\u51fa\u73b0\u5728\u521d\u59cb\u7684\u8f93\u5165\u4e2d\uff0c\u4f46\u662f\u4ecd\u7136\u53ef\u80fd\u51fa\u73b0\u5728\u6267\u884c\u671f\u3002\u3002\uff09<\/p>\n<p>\u3002\u3002\u90a3\u4e48\u770b\u6765\u540e\u671f\u4e0d\u80fd\u4e00\u76f4\u7528\u51f8\u5305\u8fdb\u884c\u64cd\u4f5c\u3002\u3002\u539f\u7b80\u5355\u591a\u8fb9\u5f62\u8fd8\u662f\u8981\u4fdd\u5b58\u7684\u3002\u3002<br \/>\n\u5148\u7ed9\u51fa\u4e3b\u7a0b\u5e8f\u3002\u3002<\/p>\n<pre class=\"brush: cpp; first-line: 448; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n.. .\r\nint main() {\r\n\r\n    \/\/freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n\r\n\twhile (scanf(&quot;%d&quot;, &amp;n) != EOF){\r\n\r\n\t    init(), cnt = int((T.x - C&#x5B;cur].x) \/ perimeter) - 1;\r\n        res = 2 * PI * cnt, T.x -= perimeter * cnt, cnt = 0;\r\n\r\n\t\twhile (cnt &lt; 2 * nn){\r\n\t\t    pivot = C&#x5B;cur], alpha = cnt ? angle&#x5B;cur] : (C&#x5B;cur+1] - C&#x5B;cur]).atan(); if (Roll()) break;\r\n\t\t\tT = rotate(T, alpha, pivot), res += alpha, ++cnt;\r\n\t\t\tif (++cur == nn) cur = 0;\r\n\t\t}\r\n\r\n        if (cnt == 2 * nn) OT(no_solution);\r\n        else OT(res);\r\n\t}\r\n}\r\n..\r\n<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u3002\u3002\u5bf9\u5468\u957f\u53d6\u6a21\u4e4b\u540e\u3002\u3002\u81f3\u591a\u518d\u8fdb\u884c 2n \u6b21 Roll() \u64cd\u4f5c\u3002\u3002<br \/>\n\u5c31\u4e00\u5b9a\u4f1a\u78b0\u5230\u90a3\u4e2a\u4ea4\u70b9\uff08\u524d\u63d0\u662f\u6709\u89e3\u3002\u3002\u4e4b\u6240\u4ee5\u518d\u8fdb\u884c 2n \u6b21\u662f\u56e0\u4e3a\u65e0\u6cd5\u5f88\u5feb\u7684\u627e\u5230\u65cb\u8f6c\u8fc7\u7a0b\u4e2d\u5728\u6700\u53f3\u8fb9\u7684\u70b9\u3002\u3002\uff09<br \/>\n\u3002\u3002<\/p>\n<p>\uff08\u987a\u4fbf\u4e00\u63d0\u3002\u3002\u6839\u636e\u8fd0\u52a8\u7684\u76f8\u5bf9\u6027\u3002\u3002 \u6240\u6709\u5bf9\u591a\u8fb9\u5f62\u8fdb\u884c\u7684\u64cd\u4f5c\u3002\u3002\u90fd\u8f6c\u5316\u4e3a\u5bf9\u5355\u4e2a T \u70b9\u3002\u3002\u8fdb\u884c\u53cd\u5411\u7684\u64cd\u4f5c\u3002\u3002\uff09<\/p>\n<p>\u552f\u4e00\u5269\u4e0b\u7684\u8fd9\u4e2a\u5de5\u4f5c\uff0c\u5c31\u662f\u7b80\u5355\u591a\u8fb9\u5f62\u548c\u4e00\u6bb5\u5f27\u7ebf\u6c42\u4ea4\u3002\u3002<br \/>\n\u3002\u3002\u679a\u4e3e\u7b80\u5355\u591a\u8fb9\u5f62\u7684\u6bcf\u4e00\u6761\u8fb9\uff08\u3002\u56e0\u4e3a\u8fd9\u4e00\u6b65\u7684\u5b58\u5728\u73b0\u5728\u7684\u590d\u6742\u5ea6\u662f O(n2) \u7684\u3002\u3002\u3002\u6709\u66f4\u597d\u65b9\u6cd5\u4e48\uff1f\u3002\u3002\uff09<\/p>\n<p>\uff08 bool Roll() \u51fd\u6570\u3002\u3002 \u3002\u3002\u5176\u4e2d alpha \u8868\u793a\u8fd9\u6b21\u65cb\u8f6c\u7684\u6700\u5927\u89d2\u5ea6\u3002\u3002beta \u8868\u793a\u6700\u5c0f\u65cb\u8f6c\u591a\u5c11\u5ea6\u53ef\u4ee5\u5230\u8fbe\u8fd9\u4e2a\u503c\u3002\u3002<br \/>\n\u3002\u3002\u5982\u679c\u6c42\u5b8c\u4ee5\u540e beta \u7684\u503c\u4ecd\u7136\u4e0d\u6ee1\u8db3\u6761\u4ef6\u3002\u3002\u90a3\u4e48\u51fd\u6570\u8fd4\u56de false\u3002\u3002\u3002\u3002\u3002\u3002\uff09<br \/>\n<a href=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/13.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"150\" data-permalink=\"https:\/\/www.shuizilong.com\/house\/archives\/zoj-3546-advanture-of-xiaoxingxing\/1-2\/\" data-orig-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/13.png\" data-orig-size=\"674,489\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/13-300x217.png\" data-large-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/13.png\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/13.png\" alt=\"\" title=\"1\" width=\"674\" height=\"489\" class=\"aligncenter size-full wp-image-150\" srcset=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/13.png 674w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/13-300x217.png 300w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/13-413x300.png 413w\" sizes=\"auto, (max-width: 674px) 100vw, 674px\" \/><\/a><\/p>\n<p>\u90a3\u4e48\u73b0\u5728\u552f\u4e00\u5269\u4e0b\u7684\u5de5\u4f5c\u5c31\u662f\u3002\u3002\u7ebf\u6bb5\u548c\u5f27\u7ebf\u6c42\u4ea4\u3002\u3002<br \/>\n(\u3002\u3002\u6211\u53d1\u73b0\u5982\u679c\u7ebf\u6bb5\u7684\u5ef6\u957f\u7ebf\u540c\u5706\u5fc3\u5728\u4e00\u6761\u76f4\u7ebf\u4e0a\u7684\u8bdd\u3002\u3002\u90a3\u4e48\u8fd9\u4e2a\u95ee\u9898\u4f1a\u975e\u5e38\u597d\u5199\u3002\u3002\u3002\u3002)<\/p>\n<p><a href=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/23.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"151\" data-permalink=\"https:\/\/www.shuizilong.com\/house\/archives\/zoj-3546-advanture-of-xiaoxingxing\/2-2\/\" data-orig-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/23.png\" data-orig-size=\"246,373\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"2\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/23-197x300.png\" data-large-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/23.png\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/23.png\" alt=\"\" title=\"2\" width=\"246\" height=\"373\" class=\"aligncenter size-full wp-image-151\" srcset=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/23.png 246w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/23-197x300.png 197w\" sizes=\"auto, (max-width: 246px) 100vw, 246px\" \/><\/a><\/p>\n<p>\u3002\u3002\u3002\u3002\u5bf9\u4e8e\u8fd9\u4e2a\u4e00\u822c\u7684\u60c5\u51b5\u3002\u3002\u6211\u4eec\u53d1\u73b0\u662f\u4e00\u4e2a\u5b9a\u6bd4\u5206\u70b9\u7684\u95ee\u9898\u3002\u3002<br \/>\n\u3002\u3002\u3002\u3002\u3002\u7136\u540e\u53d1\u73b0\u8fd9\u91cc\u8981\u89e3\u8fd9\u4e2a\u4e09\u89d2\u5f62\u3002\u3002<br \/>\n\u3002\u3002\u4f46\u662f\u8fd9\u4e48\u590d\u6742\u7684\u4e09\u89d2\u5f62\u95ee\u9898\u3002\u3002\u6211\u663e\u7136\u662f\u4e0d\u4f1a\u89e3\u7684\u3002\u3002\u3002\u3002<\/p>\n<p><a href=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/31.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"152\" data-permalink=\"https:\/\/www.shuizilong.com\/house\/archives\/zoj-3546-advanture-of-xiaoxingxing\/attachment\/3\/\" data-orig-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/31.png\" data-orig-size=\"777,597\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"3\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/31-300x230.png\" data-large-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/31.png\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/31.png\" alt=\"\" title=\"3\" width=\"777\" height=\"597\" class=\"aligncenter size-full wp-image-152\" srcset=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/31.png 777w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/31-300x230.png 300w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/31-390x300.png 390w\" sizes=\"auto, (max-width: 777px) 100vw, 777px\" \/><\/a><\/p>\n<p>\u3002\u3002\u3002\u3002\u6ca1\u529e\u6cd5\u4e86\u3002\u3002\u53ea\u597d\u770b\u770b\u6709\u6ca1\u6709\u522b\u7684\u65b9\u6cd5\u3002\u3002\u3002\u518d\u591a\u753b\u51e0\u6761\u7ebf\u3002\u3002<\/p>\n<p><a href=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/4.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"153\" data-permalink=\"https:\/\/www.shuizilong.com\/house\/archives\/zoj-3546-advanture-of-xiaoxingxing\/attachment\/4\/\" data-orig-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/4.png\" data-orig-size=\"781,564\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"4\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/4-300x216.png\" data-large-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/4.png\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/4.png\" alt=\"\" title=\"4\" width=\"781\" height=\"564\" class=\"aligncenter size-full wp-image-153\" srcset=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/4.png 781w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/4-300x216.png 300w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/10\/4-415x300.png 415w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/a><\/p>\n<p>\uff08\u3002\u6b63\u786e\u7684\u65b9\u6cd5\u662f\u8fc7\u6e90\u70b9 O\uff08\u4e5f\u5c31\u662f\u65cb\u8f6c\u4e2d\u5fc3 pivot\u3002\u3002\uff09\u505a\u7ebf\u6bb5\u7684\u5782\u8db3 O&#8217;\u3002\u3002<br \/>\n\u3002\u3002\u3002\u3002\u7136\u540e O&#8217; \u5230 T&#8217; \u7684\u65b9\u5411\u5411\u91cf\u662f\u53ef\u4ee5\u901a\u8fc7\u56fe\u4e2d\u7684\u7ea2\u4e09\u7b97\u51fa\u6765\u7684\u3002\u3002<\/p>\n<p>\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86\u3002<\/p>\n<p>\u3002\u3002\uff08\u4f46\u662f\u679c\u7136\u8fd8\u662f\u597d\u590d\u6742\u597d\u590d\u6742\u3002\u3002\u3002\u3002\uff09\u3002\u3002<\/p>\n<pre class=\"brush: cpp; collapse: true; light: false; title: ZOJ 3546; toolbar: true; notranslate\" title=\"ZOJ 3546\">\r\n\/** ` Micro Mezzo Macro Flation -- Overheated Economy ., **\/\r\n\r\n#include &lt;algorithm&gt;\r\n#include &lt;iostream&gt;\r\n#include &lt;iomanip&gt;\r\n#include &lt;sstream&gt;\r\n#include &lt;cstring&gt;\r\n#include &lt;cstdio&gt;\r\n#include &lt;string&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;bitset&gt;\r\n#include &lt;queue&gt;\r\n#include &lt;stack&gt;\r\n#include &lt;cmath&gt;\r\n#include &lt;ctime&gt;\r\n#include &lt;list&gt;\r\n#include &lt;set&gt;\r\n#include &lt;map&gt;\r\n\r\nusing namespace std;\r\n\r\n#define REP(i, n) for (int i=0;i&lt;int(n);++i)\r\n#define FOR(i, a, b) for (int i=int(a);i&lt;int(b);++i)\r\n#define DWN(i, b, a) for (int i=int(b-1);i&gt;=int(a);--i)\r\n#define REP_1(i, n) for (int i=1;i&lt;=int(n);++i)\r\n#define FOR_1(i, a, b) for (int i=int(a);i&lt;=int(b);++i)\r\n#define DWN_1(i, b, a) for (int i=int(b);i&gt;=int(a);--i)\r\n#define REP_C(i, n) for (int n____=int(n),i=0;i&lt;n____;++i)\r\n#define FOR_C(i, a, b) for (int b____=int(b),i=a;i&lt;b____;++i)\r\n#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i&gt;=a____;--i)\r\n#define REP_N(i, n) for (i=0;i&lt;int(n);++i)\r\n#define FOR_N(i, a, b) for (i=int(a);i&lt;int(b);++i)\r\n#define DWN_N(i, b, a) for (i=int(b-1);i&gt;=int(a);--i)\r\n#define REP_1_C(i, n) for (int n____=int(n),i=1;i&lt;=n____;++i)\r\n#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i&lt;=b____;++i)\r\n#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i&gt;=a____;--i)\r\n#define REP_1_N(i, n) for (i=1;i&lt;=int(n);++i)\r\n#define FOR_1_N(i, a, b) for (i=int(a);i&lt;=int(b);++i)\r\n#define DWN_1_N(i, b, a) for (i=int(b);i&gt;=int(a);--i)\r\n#define REP_C_N(i, n) for (n____=int(n),i=0;i&lt;n____;++i)\r\n#define FOR_C_N(i, a, b) for (b____=int(b),i=a;i&lt;b____;++i)\r\n#define DWN_C_N(i, b, a) for (a____=int(a),i=b-1;i&gt;=a____;--i)\r\n#define REP_1_C_N(i, n) for (n____=int(n),i=1;i&lt;=n____;++i)\r\n#define FOR_1_C_N(i, a, b) for (b____=int(b),i=a;i&lt;=b____;++i)\r\n#define DWN_1_C_N(i, b, a) for (a____=int(a),i=b;i&gt;=a____;--i)\r\n\r\n#define DO(n) while(n--)\r\n#define DO_C(n) int n____ = n; while(n____--)\r\n#define TO(i, a, b) int s_=a&lt;b?1:-1,b_=b+s_;for(int i=a;i!=b_;i+=s_)\r\n#define TO_1(i, a, b) int s_=a&lt;b?1:-1,b_=b;for(int i=a;i!=b_;i+=s_)\r\n#define SQZ(i, j, a, b) for (int i=int(a),j=int(b)-1;i&lt;j;++i,--j)\r\n#define SQZ_1(i, j, a, b) for (int i=int(a),j=int(b);i&lt;=j;++i,--j)\r\n#define REP_2(i, j, n, m) REP(i, n) REP(j, m)\r\n#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)\r\n\r\n#define ALL(A) A.begin(), A.end()\r\n#define LLA(A) A.rbegin(), A.rend()\r\n#define CPY(A, B) memcpy(A, B, sizeof(A))\r\n#define INS(A, P, B) A.insert(A.begin() + P, B)\r\n#define ERS(A, P) A.erase(A.begin() + P)\r\n#define BSC(A, X) find(ALL(A), X) \/\/ != A.end()\r\n#define CTN(T, x) (T.find(x) != T.end())\r\n#define SZ(A) int(A.size())\r\n#define PB push_back\r\n#define MP(A, B) make_pair(A, B)\r\n\r\n#define Rush int T____; RD(T____); DO(T____)\r\n#pragma comment(linker, &quot;\/STACK:36777216&quot;)\r\n#pragma GCC optimize (&quot;O2&quot;)\r\n#define Ruby system(&quot;ruby main.rb&quot;)\r\n#define Haskell system(&quot;runghc main.hs&quot;)\r\n#define Pascal system(&quot;fpc main.pas&quot;)\r\n\r\ntypedef long long LL;\r\ntypedef double DB;\r\ntypedef unsigned UINT;\r\ntypedef unsigned long long ULL;\r\n\r\ntypedef vector&lt;int&gt; VI;\r\ntypedef vector&lt;char&gt; VC;\r\ntypedef vector&lt;string&gt; VS;\r\ntypedef vector&lt;LL&gt; VL;\r\ntypedef vector&lt;DB&gt; VD;\r\ntypedef set&lt;int&gt; SI;\r\ntypedef set&lt;string&gt; SS;\r\ntypedef set&lt;LL&gt; SL;\r\ntypedef set&lt;DB&gt; SD;\r\ntypedef map&lt;int, int&gt; MII;\r\ntypedef map&lt;string, int&gt; MSI;\r\ntypedef map&lt;LL, int&gt; MLI;\r\ntypedef map&lt;DB, int&gt; MDI;\r\ntypedef map&lt;int, bool&gt; MIB;\r\ntypedef map&lt;string, bool&gt; MSB;\r\ntypedef map&lt;LL, bool&gt; MLB;\r\ntypedef map&lt;DB, bool&gt; MDB;\r\ntypedef pair&lt;int, int&gt; PII;\r\ntypedef pair&lt;int, bool&gt; PIB;\r\ntypedef vector&lt;PII&gt; VII;\r\ntypedef vector&lt;VI&gt; VVI;\r\ntypedef vector&lt;VII&gt; VVII;\r\ntypedef set&lt;PII&gt; SII;\r\ntypedef map&lt;PII, int&gt; MPIII;\r\ntypedef map&lt;PII, bool&gt; MPIIB;\r\n\r\n\r\n\/** I\/O Accelerator **\/\r\n\r\n\/* ... :&quot; We are I\/O Accelerator ... Use us at your own risk ;) ... &quot; .. *\/\r\n\r\ntemplate&lt;class T&gt; inline void RD(T &amp;);\r\ntemplate&lt;class T&gt; inline void OT(const T &amp;);\r\n\r\ninline int RD(){ int x; RD(x); return x;}\r\ntemplate&lt;class T&gt; inline T&amp; _RD(T &amp;x){ RD(x); return x;}\r\ninline void RC(char &amp;c){scanf(&quot; %c&quot;, &amp;c);}\r\ninline void RS(char *s){scanf(&quot;%s&quot;, s);}\r\n\r\ntemplate&lt;class T0, class T1&gt; inline void RD(T0 &amp;x0, T1 &amp;x1){RD(x0), RD(x1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2){RD(x0), RD(x1), RD(x2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3){RD(x0), RD(x1), RD(x2), RD(x3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5, T6 &amp;x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);}\r\ntemplate&lt;class T0, class T1&gt; inline void OT(T0 &amp;x0, T1 &amp;x1){OT(x0), OT(x1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2){OT(x0), OT(x1), OT(x2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3){OT(x0), OT(x1), OT(x2), OT(x3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5, T6 &amp;x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}\r\n\r\ntemplate&lt;class T&gt; inline void RST(T &amp;A){memset(A, 0, sizeof(A));}\r\ntemplate&lt;class T0, class T1&gt; inline void RST(T0 &amp;A0, T1 &amp;A1){RST(A0), RST(A1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){RST(A0), RST(A1), RST(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){RST(A0), RST(A1), RST(A2), RST(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}\r\n\r\ntemplate&lt;class T&gt; inline void CLR(T &amp;A){A.clear();}\r\ntemplate&lt;class T0, class T1&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1){CLR(A0), CLR(A1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){CLR(A0), CLR(A1), CLR(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}\r\ntemplate&lt;class T&gt; inline void CLR(T &amp;A, int n){REP(i, n) CLR(A&#x5B;i]);}\r\ntemplate&lt;class T&gt; inline void FLC(T &amp;A, int x){memset(A, x, sizeof(A));}\r\ntemplate&lt;class T0, class T1&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, int x){FLC(A0, x), FLC(A1, x);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){FLC(A0), FLC(A1), FLC(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){FLC(A0), FLC(A1), FLC(A2), FLC(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5), FLC(A6);}\r\n\r\ntemplate&lt;class T&gt; inline void SRT(T &amp;A){sort(ALL(A));}\r\ntemplate&lt;class T, class C&gt; inline void SRT(T &amp;A, C B){sort(ALL(A), B);}\r\n\r\n\r\n\/** Add - On **\/\r\n\r\nconst int MOD = 1000000007;\r\nconst int INF = 0x7fffffff;\r\nconst DB EPS = 1e-6;\r\nconst DB OO = 1e15;\r\nconst DB PI = M_PI;\r\n\r\n\/\/ &lt;&lt;= ` 0. Daily Use .,\r\n\r\ntemplate&lt;class T&gt; inline void checkMin(T &amp;a,const T b){if (b&lt;a) a=b;}\r\ntemplate&lt;class T&gt; inline void checkMax(T &amp;a,const T b){if (b&gt;a) a=b;}\r\ntemplate &lt;class T, class C&gt; inline void checkMin(T&amp; a, const T b, C c){if (c(b,a)) a = b;}\r\ntemplate &lt;class T, class C&gt; inline void checkMax(T&amp; a, const T b, C c){if (c(a,b)) a = b;}\r\ntemplate&lt;class T&gt; inline T min(T a, T b, T c){return min(min(a, b), c);}\r\ntemplate&lt;class T&gt; inline T max(T a, T b, T c){return max(max(a, b), c);}\r\ntemplate&lt;class T&gt; inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}\r\ntemplate&lt;class T&gt; inline T sqr(T a){return a*a;}\r\ntemplate&lt;class T&gt; inline T cub(T a){return a*a*a;}\r\nint Ceil(int x, int y){return (x - 1) \/ y + 1;}\r\n\r\n\/\/ &lt;&lt;= ` 1. Bitwise Operation .,\r\n\r\ninline bool _1(int x, int i){return x &amp; 1&lt;&lt;i;}\r\ninline int _1(int i){return 1&lt;&lt;i;}\r\ninline int _U(int i){return _1(i) - 1;};\r\n\r\ninline int count_bits(int x){\r\n    x = (x &amp; 0x55555555) + ((x &amp; 0xaaaaaaaa) &gt;&gt; 1);\r\n    x = (x &amp; 0x33333333) + ((x &amp; 0xcccccccc) &gt;&gt; 2);\r\n    x = (x &amp; 0x0f0f0f0f) + ((x &amp; 0xf0f0f0f0) &gt;&gt; 4);\r\n    x = (x &amp; 0x00ff00ff) + ((x &amp; 0xff00ff00) &gt;&gt; 8);\r\n    x = (x &amp; 0x0000ffff) + ((x &amp; 0xffff0000) &gt;&gt; 16);\r\n    return x;\r\n}\r\n\r\ntemplate&lt;class T&gt; inline T low_bit(T x) {\r\n    return x &amp; -x;\r\n}\r\n\r\ntemplate&lt;class T&gt; inline T high_bit(T x) {\r\n    T p = low_bit(x);\r\n    while (p != x) x -= p, p = low_bit(x);\r\n    return p;\r\n}\r\n\r\n\/\/ &lt;&lt;= ` 2. Modular Arithmetic Basic .,\r\n\r\ninline void INC(int &amp;a, int b){a += b; if (a &gt;= MOD) a -= MOD;}\r\ninline int sum(int a, int b){a += b; if (a &gt;= MOD) a -= MOD; return a;}\r\ninline void DEC(int &amp;a, int b){a -= b; if (a &lt; 0) a += MOD;}\r\ninline int dff(int a, int b){a -= b; if (a &lt; 0) a  += MOD; return a;}\r\ninline void MUL(int &amp;a, int b){a = int((LL)a * b % MOD);}\r\ninline int pdt(int a, int b){return int((LL)a * b % MOD);}\r\n\r\n\/\/ &lt;&lt;= '9. Comutational Geometry .,\r\n\r\nstruct Po; struct Line; struct Seg;\r\n\r\ninline int sgn(DB x){return x &lt; -EPS ? -1 : x &gt; EPS;}\r\ninline int sgn(DB x, DB y){return sgn(x - y);}\r\n\r\nstruct Po{\r\n    DB x, y;\r\n    Po(DB _x = 0, DB _y = 0):x(_x), y(_y){}\r\n\r\n    friend istream&amp; operator &gt;&gt;(istream&amp; in, Po &amp;p){return in &gt;&gt; p.x &gt;&gt; p.y;}\r\n    friend ostream&amp; operator &lt;&lt;(ostream&amp; out, Po p){return out &lt;&lt; &quot;(&quot; &lt;&lt; p.x &lt;&lt; &quot;, &quot; &lt;&lt; p.y &lt;&lt; &quot;)&quot;;}\r\n\r\n    friend bool operator ==(Po, Po);\r\n    friend Po operator +(Po, Po);\r\n    friend Po operator -(Po, Po);\r\n    friend Po operator *(Po, DB);\r\n    friend Po operator \/(Po, DB);\r\n\r\n    bool operator &lt; (const Po &amp;rhs) const{return sgn(x, rhs.x) &lt; 0 || sgn(x, rhs.x) == 0 &amp;&amp; sgn(y, rhs.y) &lt; 0;}\r\n    Po&amp; operator +=(Po rhs){x += rhs.x, y += rhs.y;}\r\n    Po&amp; operator -=(Po rhs){x -= rhs.x, y -= rhs.y;}\r\n    Po&amp; operator *=(DB k){x *= k, y *= k;}\r\n    Po&amp; operator \/=(DB k){x \/= k, y \/= k;}\r\n\r\n    DB length_sqr(){return sqr(x) + sqr(y);}\r\n    DB length(){return sqrt(length_sqr());}\r\n\r\n    DB atan(){\r\n        return atan2(y, x);\r\n    }\r\n\r\n    void input(){\r\n        int _x, _y; scanf(&quot;%d %d&quot;, &amp;_x, &amp;_y);\r\n        x = _x, y = _y;\r\n    }\r\n};\r\n\r\nbool operator ==(Po a, Po b){return sgn(a.x - b.x) == 0 &amp;&amp; sgn(a.y - b.y) == 0;}\r\nPo operator +(Po a, Po b){return Po(a.x + b.x, a.y + b.y);}\r\nPo operator -(Po a, Po b){return Po(a.x - b.x, a.y - b.y);}\r\nPo operator *(Po a, DB k){return Po(a.x * k, a.y * k);}\r\nPo operator \/(Po a, DB k){return Po(a.x \/ k, a.y \/ k);}\r\n\r\nstruct Line{\r\n    Po a, b;\r\n    Line(Po _a = Po(), Po _b = Po()):a(_a), b(_b){}\r\n    Line(DB x0, DB y0, DB x1, DB y1):a(Po(x0, y0)), b(Po(x1, y1)){}\r\n    Line(Seg);\r\n};\r\n\r\nstruct Seg{\r\n    Po a, b;\r\n    Seg(Po _a = Po(), Po _b = Po()):a(_a), b(_b){}\r\n    Seg(DB x0, DB y0, DB x1, DB y1):a(Po(x0, y0)), b(Po(x1, y1)){}\r\n    Seg(Line l);\r\n\r\n    DB length(){return (b - a).length();}\r\n};\r\n\r\nLine::Line(Seg l):a(l.a), b(l.b){}\r\nSeg::Seg(Line l):a(l.a), b(l.b){}\r\n\r\n\r\n#define innerProduct dot\r\n#define scalarProduct dot\r\n#define dotProduct dot\r\n#define outerProduct det\r\n#define crossProduct det\r\n\r\ninline DB dot(DB x1, DB y1, DB x2, DB y2){return x1 * x2 + y1 * y2;}\r\ninline DB dot(Po a, Po b){return dot(a.x, b.y, b.x, b.y);}\r\ninline DB dot(Po p0, Po p1, Po p2){return dot(p1 - p0, p2 - p0);}\r\ninline DB dot(Line l1, Line l2){return dot(l1.b - l1.a, l2.b - l2.a);}\r\ninline DB det(DB x1, DB y1, DB x2, DB y2){return x1 * y2 - x2 * y1;}\r\ninline DB det(Po a, Po b){return det(a.x, a.y, b.x, b.y);}\r\ninline DB det(Po p0, Po p1, Po p2){return det(p1 - p0, p2 - p0);}\r\ninline DB det(Line l1, Line l2){return det(l1.b - l1.a, l2.b - l2.a);}\r\n\r\ntemplate&lt;class T1, class T2&gt; inline DB dist(T1 x, T2 y){return sqrt(dist_sqr(x, y));}\r\n\r\ninline DB dist_sqr(Po a, Po b){return sqr(a.x - b.x) + sqr(a.y - b.y);}\r\ninline DB dist_sqr(Po p, Line l){Po v0 = l.b - l.a, v1 = p - l.a; return sqr(fabs(det(v0, v1))) \/ v0.length_sqr();}\r\ninline DB dist_sqr(Po p, Seg l){\r\n    Po v0 = l.b - l.a, v1 = p - l.a, v2 = p - l.b;\r\n    if (sgn(dot(v0, v1)) * sgn(dot(v0, v2)) &lt;= 0) return dist_sqr(p, Line(l));\r\n    else return min(v1.length_sqr(), v2.length_sqr());\r\n}\r\n\r\ninline DB dist_sqr(Line l, Po p){\r\n    return dist_sqr(p, l);\r\n}\r\n\r\ninline DB dist_sqr(Line l1, Line l2){\r\n    if (sgn(det(l1, l2)) != 0) return 0;\r\n    return dist_sqr(l1.a, l2);\r\n}\r\ninline DB dist_sqr(Line l1, Seg l2){\r\n    Po v0 = l1.b - l1.a, v1 = l2.a - l1.a, v2 = l2.b - l1.a; DB c1 = det(v0, v1), c2 = det(v0, v2);\r\n    return sgn(c1) != sgn(c2) ? 0 : sqr(min(fabs(c1), fabs(c2))) \/ v0.length_sqr();\r\n}\r\n\r\ninline DB dist_sqr(Seg l, Po p){\r\n    return dist_sqr(p, l);\r\n}\r\n\r\ninline DB dist_sqr(Seg l1, Line l2){\r\n    return dist_sqr(l2, l1);\r\n}\r\n\r\nbool isIntersect(Seg l1, Seg l2){\r\n\r\n    \/\/if (l1.a == l2.a || l1.a == l2.b || l1.b == l2.a || l1.b == l2.b) return true;\r\n\r\n    return\r\n        min(l1.a.x, l1.b.x) &lt;= max(l2.a.x, l2.b.x) &amp;&amp;\r\n        min(l2.a.x, l2.b.x) &lt;= max(l1.a.x, l1.b.x) &amp;&amp;\r\n        min(l1.a.y, l1.b.y) &lt;= max(l2.a.y, l2.b.y) &amp;&amp;\r\n        min(l2.a.y, l2.b.y) &lt;= max(l1.a.y, l1.b.y) &amp;&amp;\r\n    sgn( det(l1.a, l2.a, l2.b) ) * sgn( det(l1.b, l2.a, l2.b) ) &lt;= 0 &amp;&amp;\r\n    sgn( det(l2.a, l1.a, l1.b) ) * sgn( det(l2.b, l1.a, l1.b) ) &lt;= 0;\r\n\r\n}\r\n\r\ninline DB dist_sqr(Seg l1, Seg l2){\r\n    if (isIntersect(l1, l2)) return 0;\r\n    else return min(dist_sqr(l1.a, l2), dist_sqr(l1.b, l2), dist_sqr(l2.a, l1), dist_sqr(l2.b, l1));\r\n}\r\n\r\ninline bool isOnseg(const Po &amp;p, const Seg &amp;l){\r\n\treturn sgn(det(p, l.a, l.b)) == 0 &amp;&amp;\r\n        sgn(l.a.x, p.x) * sgn(l.b.x, p.x) &lt;= 0 &amp;&amp; sgn(l.a.y, p.y) * sgn(l.b.y, p.y) &lt;= 0;\r\n}\r\n\r\ninline Po intersect(const Line &amp;l1, const Line &amp;l2){\r\n    return l1.a + (l1.b - l1.a) * (det(l2.a, l1.a, l2.b) \/ det(l2, l1));\r\n}\r\n\r\n\/\/ perpendicular foot\r\ninline Po intersect(const Po &amp; p, const Line &amp;l){\r\n\treturn intersect(Line(p, p + Po(l.a.y - l.b.y, l.b.x - l.a.x)), l);\r\n}\r\n\r\ninline Po rotate(Po p, DB alpha, Po o = Po()){\r\n    p.x -= o.x, p.y -= o.y;\r\n    return Po(p.x * cos(alpha) - p.y * sin(alpha), p.y * cos(alpha) + p.x * sin(alpha)) + o;\r\n}\r\n\r\n\r\n\/\/ &lt;&lt;= ' 0. I\/O Accelerator interface .,\r\n\r\ntemplate&lt;class T&gt; inline void RD(T &amp;x){\r\n    \/\/cin &gt;&gt; x;\r\n    \/\/scanf(&quot;%d&quot;, &amp;x);\r\n    char c; for (c = getchar(); c &lt; '0'; c = getchar()); x = c - '0'; for (c = getchar(); c &gt;= '0'; c = getchar()) x = x * 10 + c - '0';\r\n    \/\/char c; c = getchar(); x = c - '0'; for (c = getchar(); c &gt;= '0'; c = getchar()) x = x * 10 + c - '0';\r\n\r\n}\r\n\r\nconst DB no_solution = -1;\r\n\r\nint ____Case;\r\ntemplate&lt;class T&gt; inline void OT(const T &amp;x){\r\n\r\n    printf(&quot;Case %d: &quot;, ++____Case);\r\n\r\n    if (x == no_solution){\r\n        puts(&quot;Impossible&quot;);\r\n    }\r\n    else {\r\n        printf(&quot;%.2lf\\n&quot;, x \/ PI * 180);\r\n    }\r\n}\r\n\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 109;\r\n\r\nPo P&#x5B;N], P_&#x5B;N], C&#x5B;N], T; DB _, angle&#x5B;N], perimeter;\r\nint cur, cnt; Po pivot; DB alpha, res;\r\nint n, nn;\r\n\r\n#define p0 P_&#x5B;0]\r\nbool cpPolar(const Po &amp;p1, const Po &amp;p2){\r\n    int t = sgn(crossProduct(p0, p1, p2));\r\n    if (t == 0) return dist_sqr(p0, p1) &lt; dist_sqr(p0, p2);\r\n    return t == 1;\r\n}\r\n\r\n#define O pivot\r\nbool Roll(){\r\n    DB rr = (T - O).length_sqr(), o = (T - O).atan(), beta = OO, t;\r\n\r\n\tREP(i, n){\r\n\t    Line L = Line(P&#x5B;i], P&#x5B;i + 1]);\r\n        Po O_ = intersect(O, L), D = (P&#x5B;i+1] - O).length_sqr() &gt; (P&#x5B;i] - O).length_sqr() ? P&#x5B;i+1] - P&#x5B;i] : P&#x5B;i] - P&#x5B;i+1];\r\n        D \/= D.length(), D *= sqrt(rr - dist_sqr(O, O_));\r\n\r\n        if (isOnseg(O_ + D, L)){\r\n            O_ += D, t = (O_ - O).atan() - o;\r\n            if (t &lt; 0) t += PI * 2; checkMin(beta, t);\r\n        }\r\n\t}\r\n\r\n\tif (sgn(beta, alpha) &lt;= 0){res += beta; return true;}\r\n\treturn false;\r\n}\r\n\r\nvoid init(){\r\n    REP(i, n) P&#x5B;i].input(); P&#x5B;n] = P&#x5B;0], T.input();\r\n    CPY(P_, P), iter_swap(P_, min_element(P_, P_ + n)), sort(P_ + 1, P_ + n, cpPolar);\r\n\r\n    nn = 0, C&#x5B;++nn] = P_&#x5B;0], C&#x5B;++nn] = P_&#x5B;1];\r\n\r\n    FOR(i, 2, n){\r\n        while (nn &gt;= 2 &amp;&amp; sgn(crossProduct(C&#x5B;nn-1], C&#x5B;nn], P_&#x5B;i])) &lt;= 0) --nn;\r\n        C&#x5B;++nn] = P_&#x5B;i];\r\n    }\r\n\r\n    perimeter = 0, C&#x5B;0] = C&#x5B;nn]; REP(i, nn){\r\n        if (C&#x5B;i].y == 0) cur = i;\r\n        angle&#x5B;i] = (C&#x5B;i+1] - C&#x5B;i]).atan();\r\n        perimeter += dist(C&#x5B;i], C&#x5B;i+1]);\r\n    }\r\n\r\n    angle&#x5B;-1] = angle&#x5B;nn-1];\r\n\r\n    DWN(i, nn, 0){\r\n        angle&#x5B;i] -= angle&#x5B;i-1];\r\n        if (angle&#x5B;i] &lt; -PI) angle&#x5B;i] += PI * 2;\r\n        else if (angle&#x5B;i] &gt; PI) angle&#x5B;i] -= PI * 2;\r\n    }\r\n}\r\n\r\nint main() {\r\n\r\n    \/\/freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n\r\n\twhile (scanf(&quot;%d&quot;, &amp;n) != EOF){\r\n\r\n\t    init(), cnt = int((T.x - C&#x5B;cur].x) \/ perimeter) - 1;\r\n        res = 2 * PI * cnt, T.x -= perimeter * cnt, cnt = 0;\r\n\r\n\t\twhile (cnt &lt; 2 * nn){\r\n\t\t    pivot = C&#x5B;cur], alpha = cnt ? angle&#x5B;cur] : (C&#x5B;cur+1] - C&#x5B;cur]).atan(); if (Roll()) break;\r\n\t\t\tT = rotate(T, alpha, pivot), res += alpha, ++cnt;\r\n\t\t\tif (++cur == nn) cur = 0;\r\n\t\t}\r\n\r\n        if (cnt == 2 * nn) OT(no_solution);\r\n        else OT(res);\r\n\t}\r\n}\r\n<\/pre>\n<h3>External link: <\/h3>\n<p><a href=\"http:\/\/acm.zju.edu.cn\/onlinejudge\/showProblem.do?problemCode=3546\">http:\/\/acm.zju.edu.cn\/onlinejudge\/showProblem.do?problemCode=3546<\/a><\/p>\n<h3>Further discussion: <\/h3>\n<p>\u3002\u3002\u3002\u7ffb\u6eda\u90e8\u5206\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u53ef\u4ee5\u964d\u4f4e\u5230 O(n) \u7684\u3002\u3002\u65b9\u6cd5\u662f\u4ece\u652f\u70b9\u5f00\u59cb\u3002\u3002\u6cbf\u9006\u65f6\u9488\u5bfb\u627e\u7b2c\u4e00\u6b21\u53d8\u53f7\u7684\u4f4d\u7f6e\u3002 (&#8230; sgn(dist(P[i], O) &#8211; dist(T, O)).. ) ..<br \/>\n\u8fd9\u4e2a\u90e8\u5206\u53ef\u4ee5\u7528\u5355\u8c03\u961f\u5217\u7ef4\u62a4\u3002\u3002\u3002\u4e3a\u6b64\u6211\u4eec\u9700\u8981\u4fdd\u5b58\u51f8\u5305\u70b9\u5230\u539f\u70b9\u7684\u6620\u5c04\u3002\u3002<br \/>\n\u53e6\u5916\u3002\u3002\u7528\u89e3\u4e09\u89d2\u5f62\u7684\u65b9\u6cd5\u4e5f\u662f\u53ef\u4ee5\u7ec4\u591a\u8fb9\u5f62\u4e0e\u5f27\u6c42\u4ea4\u7684\u90e8\u5206\u7684\u3002\u3002\u4f46\u662f\u6211\u73b0\u5728 WA \u4e86\u3002\u3002<br \/>\n\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: \u7ffb\u7eb8\u76d2\u95ee\u9898\uff0c\u7ed9\u5b9a\u4e00\u4e2a N \u4e2a\u9876\u70b9\u7684\u7b80\u5355\u591a\u8fb9\u5f62\uff0c\u95ee\u6cbf\u7740 x \u8f74\u8fdb\u884c\u6eda\u52a8\uff0c\u89e6\u78b0 T \u70b9\u65f6\u7ffb\u6eda\u7684\u89d2\u5ea6\u3002 \u591a\u8fb9\u5f62\u7684\u9876\u70b9\u6309\u7167\u987a\u65f6\u9488\u6216\u9006\u65f6\u9488\u7ed9\u51fa\uff0c\u4e14\u7b2c\u4e00\u4e2a\u70b9\u662f\u6e90\u70b9\uff0cT \u70b9\u4e00\u5b9a\u5728\u8fd9\u4e2a\u591a\u8fb9\u5f62\u7684\u53f3\u8fb9\uff0c\u6240\u6709\u70b9\u7684 y \u8f74\u5750\u6807 >= 0\u3002 .. ( N<\/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":[55],"tags":[25],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-zoj","tag-25"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-2n","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/147","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=147"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}