{"id":415,"date":"2013-07-18T12:05:41","date_gmt":"2013-07-18T04:05:41","guid":{"rendered":"http:\/\/blog.dayandcarrot.net\/?p=415"},"modified":"2013-07-18T12:05:41","modified_gmt":"2013-07-18T04:05:41","slug":"hdoj-1097-a-hard-puzzle","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=415","title":{"rendered":"HDOJ-1097 A hard puzzle"},"content":{"rendered":"<p><span><b>Time Limit: 2000\/1000 MS (Java\/Others)\u00a0\u00a0\u00a0\u00a0Memory Limit: 65536\/32768 K (Java\/Others)<br \/>\nTotal Submission(s): 23989\u00a0\u00a0\u00a0\u00a0Accepted Submission(s): 8466<br \/>\n<\/b><\/span><\/p>\n<div align=\"left\">Problem Description<\/div>\n<div>lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.<br \/>\nthis puzzle describes that: gave a and b,how to know the a^b&#8217;s the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.<\/div>\n<div><\/div>\n<p>&nbsp;<\/p>\n<div align=\"left\">Input<\/div>\n<div>There are mutiple test cases. Each test cases consists of two numbers a and b(0&lt;a,b&lt;=2^30)<\/div>\n<div><\/div>\n<p>&nbsp;<\/p>\n<div align=\"left\">Output<\/div>\n<div>For each test case, you should output the a^b&#8217;s last digit number.<\/div>\n<div><\/div>\n<p>&nbsp;<\/p>\n<div align=\"left\">Sample Input<\/div>\n<div>\n<div>7 66 8 800<\/div>\n<\/div>\n<div><\/div>\n<p>&nbsp;<\/p>\n<div align=\"left\">Sample Output<\/div>\n<div>\n<div>9 6<\/div>\n<\/div>\n<div><\/div>\n<p>==========================================<br \/>\n\u6b7b\u641e\u80af\u5b9a\u662f\u8981\u8d85\u65f6\u7684&#8230;.<br \/>\n\u5176\u5b9e\u4e00\u51719\u4e2a\u6570\u5b57\uff0c\u4e58\u65b9\u90fd\u662f\u6709\u89c4\u5f8b\u7684..\u5199\u7684\u4e11\u964b\u4e86\u70b9\uff0c\u4e0d\u8fc7\u80fd\u7528\u5c31\u597d^^<\/p>\n<pre>\n#include <iostream>\n#include <string.h>\nusing namespace std;\nconst int BUFFER_LENGTH = 31;\nconst int pattern_size[] = {1, 1, 4, 4, 2, 1, 1, 4, 4, 2};\nconst int pattern_0[] = {0};\nconst int pattern_1[] = {1};\nconst int pattern_2[] = {2, 4, 8, 6};\nconst int pattern_3[] = {3, 9, 7, 1};\nconst int pattern_4[] = {4, 6};\nconst int pattern_5[] = {5};\nconst int pattern_6[] = {6};\nconst int pattern_7[] = {7, 9, 3, 1};\nconst int pattern_8[] = {8, 4, 2, 6};\nconst int pattern_9[] = {9, 1};\nint main()\n{\n\tchar a[BUFFER_LENGTH];\n\tlong long b;\n\twhile(cin >> a >> b)\n\t{\n\t\tint len_a = strlen(a);\n\t\tint last_digit = a[len_a-1] - 0x30;\n\t\tint result;\n\t\tb--;\n\t\tswitch(last_digit)\n\t\t{\n\t\tcase 0:\n\t\t\tresult = pattern_0[b%pattern_size[0]];\n\t\t\tbreak;\n\t\tcase 1:\n\t\t\tresult = pattern_1[b%pattern_size[1]];\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tresult = pattern_2[b%pattern_size[2]];\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\tresult = pattern_3[b%pattern_size[3]];\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tresult = pattern_4[b%pattern_size[4]];\n\t\t\tbreak;\n\t\tcase 5:\n\t\t\tresult = pattern_5[b%pattern_size[5]];\n\t\t\tbreak;\n\t\tcase 6:\n\t\t\tresult = pattern_6[b%pattern_size[6]];\n\t\t\tbreak;\n\t\tcase 7:\n\t\t\tresult = pattern_7[b%pattern_size[7]];\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tresult = pattern_8[b%pattern_size[8]];\n\t\t\tbreak;\n\t\tcase 9:\n\t\t\tresult = pattern_9[b%pattern_size[9]];\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tresult = -1;\n\t\t}\n\t\tcout << result << endl;\n\t}\n\treturn 0;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Time Limit: 2000\/1000 MS (Java\/Others)\u00a0\u00a0\u00a0\u00a0Memory Limit: 65536\/32768 K (Java\/Others) Total Submission(s): 23989\u00a0\u00a0\u00a0\u00a0Accepted Submission(s): 8466 Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin. this puzzle describes that: gave a and b,how to know [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[138],"class_list":["post-415","post","type-post","status-publish","format-standard","hentry","category-study","tag-other-cpp"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=415"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/415\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}