{"id":540,"date":"2018-05-04T13:49:35","date_gmt":"2018-05-04T05:49:35","guid":{"rendered":"http:\/\/kylelv.com\/?p=540"},"modified":"2020-03-02T20:44:57","modified_gmt":"2020-03-02T12:44:57","slug":"bzoj-5313-%e6%96%b0fib%e6%95%b0%e5%88%97-%e6%9a%b4%e5%8a%9b","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=540","title":{"rendered":"bzoj 5313: \u65b0Fib\u6570\u5217  &#8212; \u66b4\u529b"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fdef4568800\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fdef4568800\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.kylelv.com\/?p=540\/#5313_%E6%96%B0Fib%E6%95%B0%E5%88%97\" title=\"5313: \u65b0Fib\u6570\u5217\">5313: \u65b0Fib\u6570\u5217<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=540\/#Description\" title=\"Description\">Description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=540\/#Input\" title=\"Input\">Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=540\/#Output\" title=\"Output\">Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=540\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=540\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=540\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"5313_%E6%96%B0Fib%E6%95%B0%E5%88%97\"><\/span>5313: \u65b0Fib\u6570\u5217<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a0<\/span>2 Sec\u00a0\u00a0<span class=\"green\">Memory Limit:\u00a0<\/span>16 MB<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div>\u5929\u5730\u5408\uff0c\u4e43\u6562\u4e0d\u541b\u7edd\uff1f\u6211\u4eec\u53d1\u73b0\u6c42\u51fa\u6590\u6ce2\u90a3\u5951\u6570\u5217\u5728\u67d0\u79cd\u610f\u4e49\u4e0b\u53ef\u4ee5\u4f5c\u4e3a\u89e3\u51b3\u4e00\u4e9b\u6709\u610f\u4e49\u95ee\u9898\u7684\u65b9\u6cd5\uff0c\u7279\u522b\u662f\u5728\u6a21<\/div>\n<div>5\u610f\u4e49\u4e0b\u7684\u67d0\u79cd\u7ec4\u5408\uff0c\u6216\u8bb8\u53ef\u4ee5\u7834\u89e3\u654c\u65b9\u7684\u5bc6\u7801\u7cfb\u7edf\u3002\u51fa\u9898\u4eba\u592a\u61d2\u4e86\uff0c\u5bf9\u4e8e\u7b97\u6590\u6ce2\u90a3\u5951\u6570\u5217\u8fd9\u79cd\u96be\u4e8b\uff0c\u4e0c\u80fd\u627e\u5230\u7b80<\/div>\n<div>\u4fbf\u65b9\u6cd5\uff0c\u56e0\u6b64\u4ed6\u5c31\u61d2\u5f97\u4e0c\u60f3\u505a\u4e86\uff08\u5373\u4f7f\u60f3\u505a\u53ef\u80fd\u8981\u4e70\u4e0a\u4e00\u67611PB\u7684\u5185\u5b58\u6761\uff09\u3002\u4ed6\u627e\u5230\u4e86\u5584\u4e8e\u601d\u8003\u3001 \u7528\u8ba1\u7b97\u673a\u5feb\u901f\u89e3<\/div>\n<div>\u51b3\u95ee\u9898\u7684\u4f60\uff01\u4f60\u80fd\u5e2e\u5e2e\u4ed6\u5417\uff1f<\/div>\n<div>\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u5b9a\u4e49\u4e3a F(n)=F(n-1)+F(n-2)\u3002<\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div>\u73b0\u6709Q\u4e2a\u8be2\u95ee\uff0c \u6bcf\u4e2a\u8be2\u95ee\u90fd\u7ed9\u51fa\u4e00\u4e2aQi\u3002<\/div>\n<div>\u5bf9\u4e8e\u6bcf\u4e2a\u8be2\u95ee<\/div>\n<div>\u8bf7\u4f60\u6c42\u51fa\u5e76\u8f93\u51fa\u6590\u6ce2\u90a3\u5951\u6570\u5217\u5728\u6a21 5 \u610f\u4e49\u4e0b\u7684\u7b2cQi\u9879\uff0c\u6bcf\u4e2a\u8be2\u95ee\u7684\u8f93\u51fa\u5360\u4e00\u884c\u3002<\/div>\n<div>Q&lt;=10^6 Qi&lt;=2*10^9<\/div>\n<div>\u8bf7\u7559\u610f\u672c\u9898\u6570\u636e\u8303\u56f4\u3002 \u672c\u9898\u5171\u670925\u4e2a\u6d4b\u8bd5\u70b9\u3002<\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u5982\u9898<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">9<br \/>\n1 2 3 4 5 6 7 8 9<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">1<br \/>\n1<br \/>\n2<br \/>\n3<br \/>\n0<br \/>\n3<br \/>\n3<br \/>\n1<br \/>\n4<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u597d\u4e45\u4e0d\u5199blogs\u4e86\uff0c\u6c34\u4e00\u53d1\u9898\u3002\u3002<\/p>\n<p>\u6211\u4eec\u53d1\u73b0\u53ea\u8981\u8fde\u7eed\u4e24\u4f4d\u90fd\u548c\u4e4b\u524d\u76f8\u540c\u7b54\u6848\u5c31\u5faa\u73af\u4e86\uff0c\u6240\u4ee5\u7531\u6570\u5b66\u8bc1\u660e\u5faa\u73af\u8282&lt;=5*5\uff0c\u6700\u540e\u6211\u4eec\u53d1\u73b0\u5faa\u73af\u8282\u662f20<\/p>\n<p>\u8bc1\u660e\u7684\u8bdd\uff0c\u5c31\u662f\u4e24\u4e2a\u76f8\u90bb\u7684\u6570\u53ea\u67095*5\u79cd\u672c\u8d28\u4e0d\u540c\u7684\u7ec4\u5408\uff0c\u6240\u4ee525\u4e2a\u6570\u5185\u5c31\u4f1a\u6709\u91cd\u590d\u7684<\/p>\n<p>\u597d\u6c34\u554aqaq<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;map&gt;\n#include&lt;cmath&gt;\n#include&lt;queue&gt;\n#include&lt;cstdio&gt;\n#include&lt;string&gt;\n#include&lt;cstring&gt;\n#include&lt;iostream&gt;\n#include&lt;algorithm&gt;\nusing namespace std;\n#define inf 1000000007\n#define ll long long\n#define N 100010\nchar xB[1&lt;&lt;15],*xS=xB,*xTT=xB;\n#define getc() (xS==xTT&amp;&amp;(xTT=(xS=xB)+fread(xB,1,1&lt;&lt;15,stdin),xS==xTT)?0:*xS++)\n#define isd(c) (c&gt;='0'&amp;&amp;c&lt;='9')\ninline int rd(){\n    char xchh;\n    int xaa;\n    while(xchh=getc(),!isd(xchh));(xaa=xchh-'0');\n    while(xchh=getc(),isd(xchh))xaa=xaa*10+xchh-'0';return xaa;\n}\nint Q,x;\nint f[22];\nint main()\n{\n    f[0]=1;f[1]=1;\n    for(int i=2;;i++)\n    {\n        f[i]=(f[i-1]+f[i-2])%5;\n        if(f[i]==f[1]&amp;&amp;f[i-1]==f[0]) break;\n    }\n    Q=rd();\n    while(Q--)\n    {\n        x=rd()-1;x%=20;\n        printf(\"%d\\n\",f[x]);\n    }\n    return 0;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>5313: \u65b0Fib\u6570\u5217 Time Limit:\u00a02 Sec\u00a0\u00a0Memory Limit:\u00a016 MB Des [&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":[16],"class_list":["post-540","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-16"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/540","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=540"}],"version-history":[{"count":5,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/540\/revisions"}],"predecessor-version":[{"id":584,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/540\/revisions\/584"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}