{"id":228,"date":"2016-10-19T19:19:37","date_gmt":"2016-10-19T11:19:37","guid":{"rendered":"http:\/\/kylelv.com\/?p=228"},"modified":"2017-12-13T12:55:16","modified_gmt":"2017-12-13T04:55:16","slug":"poj-1654%ef%bc%9aarea-%e5%8c%ba%e5%9f%9f-%e5%8f%89%e7%a7%af%ef%bc%88%e6%b1%82%e5%a4%9a%e8%be%b9%e5%bd%a2%e9%9d%a2%e7%a7%af%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=228","title":{"rendered":"poj 1654\uff1aArea \u533a\u57df &#8212;- \u53c9\u79ef\uff08\u6c42\u591a\u8fb9\u5f62\u9762\u79ef\uff09"},"content":{"rendered":"<h1 class=\"ptt\" lang=\"en-US\" style=\"text-align: center;\">Area<\/h1>\n<div class=\"ptt\" lang=\"en-US\"><\/div>\n<div class=\"plm\">\n<table align=\"center\">\n<tbody>\n<tr>\n<td><strong>Time Limit:<\/strong>\u00a01000MS<\/td>\n<td width=\"10px\"><\/td>\n<td><strong>Memory Limit:<\/strong>\u00a010000K<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><strong>Total Submissions:<\/strong>\u00a019398<\/td>\n<td width=\"10px\"><\/td>\n<td><strong>Accepted:<\/strong>\u00a05311<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u5229\u7528\u53c9\u79ef\u6c42\u591a\u8fb9\u5f62\u9762\u79ef\uff0c\u53ef\u4ee5\u5206\u89e3\u6210\u591a\u4e2a\u4e09\u89d2\u5f62<\/p>\n<p>\u5229\u7528\u9762\u79ef\u516c\u5f0f\uff0cS=1\/2*abs((x0*y1-x1*y0)+(x1*y2-x2*y1)&#8230;+(xn*yn-1-xn-1*yn)+(xn*y0-x0*yn))\u00a0,\u628a\u76f8\u90bb\u4e24\u70b9\u548c\u539f\u70b9\u7ec4\u6210\u4e00\u4e2a\u4e09\u89d2\u5f62\uff0c\u800c\u603b\u9762\u79ef\u662f\u8fd9n\u4e2a\u4e09\u89d2\u5f62\u9762\u79ef\u7684\u548c\uff0c\u800c\u4e09\u89d2\u5f62\u9762\u79ef\u662f\u4e24\u4e2a\u76f8\u90bb\u8fb9\u5411\u91cf\u7684\u53c9\u79ef<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<p class=\"pst\">Description<\/p>\n<div class=\"ptx\" lang=\"en-US\">You are going to compute the area of a special kind of polygon. One vertex of the polygon is the origin of the orthogonal coordinate system. From this vertex, you may go step by step to the following vertexes of the polygon until back to the initial vertex. For each step you may go North, West, South or East with step length of 1 unit, or go Northwest, Northeast, Southwest or Southeast with step length of square root of 2.<\/div>\n<div class=\"ptx\" lang=\"en-US\">\n<p>\u4f60\u8981\u8ba1\u7b97\u4e00\u79cd\u7279\u6b8a\u7684\u591a\u8fb9\u5f62\u7684\u9762\u79ef\u3002\u4e00\u4e2a\u9876\u70b9\u7684\u591a\u8fb9\u5f62\u662f\u6b63\u4ea4\u5750\u6807\u7cfb\u7684\u539f\u70b9\u3002\u4ece\u8fd9\u4e2a\u9876\u70b9,\u4f60\u53ef\u4ee5\u8d70\u4e86\u4e00\u6b65\u4e00\u6b65\u7684\u591a\u8fb9\u5f62\u7684\u9876\u70b9\u540e,\u76f4\u5230\u56de\u5230\u6700\u521d\u7684\u9876\u70b9\u3002\u4e3a\u6bcf\u4e2a\u6b65\u9aa4\u4f60\u53ef\u4ee5\u53bb\u5317\u3001\u897f\u3001\u5357\u3001\u4e1c\u4e0e\u6b65\u957f\u4e3a1\u5355\u4f4d,\u6216\u53bb\u897f\u5317,\u4e1c\u5317,\u897f\u5357\u6216\u4e1c\u5357\u221a2\u6b65\u957f\u3002<\/p>\n<p>For example, this is a legal polygon to be computed and its area is 2.5:<\/p>\n<p><center><img decoding=\"async\" src=\"http:\/\/poj.org\/images\/1654_1.jpg\" alt=\"\" \/><\/center><\/div>\n<p class=\"pst\">Input<\/p>\n<div class=\"ptx\" lang=\"en-US\">The first line of input is an integer t (1 &lt;= t &lt;= 20), the number of the test polygons. Each of the following lines contains a string composed of digits 1-9 describing how the polygon is formed by walking from the origin. Here 8, 2, 6 and 4 represent North, South, East and West, while 9, 7, 3 and 1 denote Northeast, Northwest, Southeast and Southwest respectively. Number 5 only appears at the end of the sequence indicating the stop of walking. You may assume that the input polygon is valid which means that the endpoint is always the start point and the sides of the polygon are not cross to each other.Each line may contain up to 1000000 digits.<\/div>\n<p class=\"pst\">Output<\/p>\n<div class=\"ptx\" lang=\"en-US\">For each polygon, print its area on a single line.<\/div>\n<p class=\"pst\">Sample Input<\/p>\n<pre class=\"sio\">4\r\n5\r\n825\r\n6725\r\n6244865<\/pre>\n<p class=\"pst\">Sample Output<\/p>\n<pre class=\"sio\">0\r\n0\r\n0.5\r\n2<\/pre>\n<pre class=\"lang:c++ decode:true \">#include&lt;cstdio&gt;\r\n#define ll long long\r\nll n,m,t,x1,x2,y1,y2,ans;\r\nint dx[10]={0,1,1,1,0,0,0,-1,-1,-1};\r\nint dy[10]={0,-1,0,1,-1,0,1,-1,0,1};\r\nll abs(ll a){return a&lt;0?-a:a;}\r\nint main()\r\n{\r\n    scanf(\"%d\",&amp;t);\r\n    for(int i=0;i&lt;t;i++)\r\n    {\r\n        x2=y2=ans=0;\r\n        char p=getchar();\r\n        while(p=getchar())\r\n        {\r\n            ll tmp=p-'0';\r\n            if(tmp==5) break;\r\n            x1=x2,y1=y2;\r\n            x2+=dx[tmp],y2+=dy[tmp];\r\n            ans+=(x1*y2-x2*y1);\r\n        }\r\n        ans=abs(ans);\r\n        if(ans%2==0) printf(\"%lld\\n\",ans\/2);\r\n        else printf(\"%lld.5\\n\",ans\/2);\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Area Time Limit:\u00a01000MS Memory Limit:\u00a010000K Total Subm [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[8],"class_list":["post-228","post","type-post","status-publish","format-standard","hentry","category-poj","tag-8"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=228"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions"}],"predecessor-version":[{"id":247,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions\/247"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}