{"id":74,"date":"2023-11-02T22:45:00","date_gmt":"2023-11-02T14:45:00","guid":{"rendered":"http:\/\/www.cmd137blog.top\/?p=74"},"modified":"2024-03-31T22:48:09","modified_gmt":"2024-03-31T14:48:09","slug":"%e3%80%90bjfuoj%e3%80%91%e5%b0%8f%e5%ad%99%e5%90%8c%e5%ad%a6%ef%bc%88%e8%b4%aa%e5%bf%83%e7%ae%97%e6%b3%95%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.cmd137blog.top\/?p=74","title":{"rendered":"\u3010BJFUOJ\u3011\u5c0f\u5b59\u540c\u5b66\uff08\u8d2a\u5fc3\u7b97\u6cd5\uff09"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u4e00\u3001\u9898\u76ee\uff1a<\/h1>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/www.cmd137blog.top\/wp-content\/uploads\/2024\/03\/bf5a612ed5a54a97bcd0511fd8b12878-1024x533.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"533\" data-original=\"http:\/\/www.cmd137blog.top\/wp-content\/uploads\/2024\/03\/bf5a612ed5a54a97bcd0511fd8b12878-1024x533.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-75\" style=\"aspect-ratio:1;width:540px;height:auto\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e8c\u3001\u601d\u8def\uff1a<\/h1>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u7684\u4e3b\u8981\u601d\u8def\u662f\u89e3\u51b3\u4e00\u4e2a\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u4f4d\u7f6e n\uff0c\u8ba1\u7b97\u8fbe\u5230\u8be5\u4f4d\u7f6e\u7684\u6700\u5c0f\u8df3\u8dc3\u6b21\u6570\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\u7684\u903b\u8f91\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u9996\u5148\uff0c\u901a\u8fc7 <code>cin<\/code> \u8bed\u53e5\u8bfb\u53d6\u4e00\u4e2a\u6574\u6570 t\uff0c\u8868\u793a\u6d4b\u8bd5\u7528\u4f8b\u7684\u6570\u91cf\u3002<\/li>\n\n\n\n<li>\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528\u4e00\u4e2a while \u5faa\u73af\uff0c\u91cd\u590d\u6267\u884c\u4e0b\u9762\u7684\u64cd\u4f5c t \u6b21\u3002<\/li>\n\n\n\n<li>\u5728\u5faa\u73af\u5185\u90e8\uff0c\u901a\u8fc7 <code>cin<\/code> \u8bed\u53e5\u8bfb\u53d6\u4e00\u4e2a\u6574\u6570 n\uff0c\u8868\u793a\u76ee\u6807\u4f4d\u7f6e\u3002<\/li>\n\n\n\n<li>\u7136\u540e\uff0c\u5f00\u59cb\u8ba1\u7b97\u6700\u5c0f\u8df3\u8dc3\u6b21\u6570\u3002\u9996\u5148\u68c0\u67e5 n \u7684\u503c\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c n \u7b49\u4e8e 1\uff0c\u8fd4\u56de\u503c\u4e3a 2\uff0c\u8868\u793a\u53ea\u9700\u4e00\u6b21\u8df3\u8dc3\u5373\u53ef\u5230\u8fbe\u76ee\u6807\u4f4d\u7f6e\u3002<\/li>\n\n\n\n<li>\u5982\u679c n \u7b49\u4e8e 2\uff0c\u8fd4\u56de\u503c\u4e3a 1\uff0c\u8868\u793a\u53ea\u9700\u4e00\u6b21\u8df3\u8dc3\u5373\u53ef\u5230\u8fbe\u76ee\u6807\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5982\u679c n \u4e0d\u7b49\u4e8e 1 \u6216 2\uff0c\u6211\u4eec\u9700\u8981\u7ee7\u7eed\u8ba1\u7b97\u8df3\u8dc3\u6b21\u6570\u3002\u9996\u5148\uff0c\u4f7f\u7528\u53d6\u6a21\u8fd0\u7b97\u7b26 <code>%<\/code> \u8ba1\u7b97 n \u9664\u4ee5 3 \u7684\u4f59\u6570\uff0c\u5e76\u5c06\u7ed3\u679c\u4fdd\u5b58\u5728\u53d8\u91cf t \u4e2d\u3002<\/li>\n\n\n\n<li>\u5982\u679c t \u7b49\u4e8e 0\uff0c\u8868\u793a n \u53ef\u4ee5\u88ab 3 \u6574\u9664\uff0c\u5373 n \u662f 3 \u7684\u500d\u6570\u3002\u6b64\u65f6\uff0c\u8df3\u8dc3\u6b21\u6570\u4e3a n \u9664\u4ee5 3\u3002<\/li>\n\n\n\n<li>\u5982\u679c t \u4e0d\u7b49\u4e8e 0\uff0c\u8868\u793a n \u4e0d\u80fd\u88ab 3 \u6574\u9664\u3002\u8fd9\u65f6\uff0c\u6211\u4eec\u9700\u8981\u518d\u8fdb\u884c\u4e00\u6b21\u989d\u5916\u7684\u8df3\u8dc3\uff0c\u6240\u4ee5\u8df3\u8dc3\u6b21\u6570\u4e3a n \u9664\u4ee5 3 \u52a0\u4e0a 1\u3002<\/li>\n\n\n\n<li><code>solve()<\/code> \u51fd\u6570\u8fd4\u56de\u8ba1\u7b97\u5f97\u5230\u7684\u6700\u5c0f\u8df3\u8dc3\u6b21\u6570\u3002<\/li>\n\n\n\n<li>\u5728\u5faa\u73af\u7ed3\u675f\u540e\uff0c\u901a\u8fc7 <code>cout<\/code> \u8bed\u53e5\u548c <code>endl<\/code> \u6362\u884c\u7b26\u8f93\u51fa\u6700\u5c0f\u8df3\u8dc3\u6b21\u6570\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u603b\u4f53\u800c\u8a00\uff0c\u8fd9\u6bb5\u4ee3\u7801\u4f7f\u7528\u4e86\u7b80\u5355\u7684\u8f93\u5165\u548c\u8f93\u51fa\u64cd\u4f5c\uff0c\u901a\u8fc7\u6761\u4ef6\u5224\u65ad\u548c\u8fd0\u7b97\u7b26\uff0c\u4ee5\u53ca\u4e00\u4e2a while \u5faa\u73af\uff0c\u8ba1\u7b97\u8fbe\u5230\u76ee\u6807\u4f4d\u7f6e\u7684\u6700\u5c0f\u8df3\u8dc3\u6b21\u6570\u3002\u5e0c\u671b\u8fd9\u4e2a\u7b80\u8981\u7684\u8bf4\u660e\u80fd\u591f\u5e2e\u52a9\u4f60\u7406\u89e3\u4ee3\u7801\u7684\u601d\u8def\u3002\u5982\u679c\u8fd8\u6709\u5176\u4ed6\u95ee\u9898\uff0c\u8bf7\u968f\u65f6\u63d0\u95ee\uff01<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e09\u3001\u6e90\u7801\uff1a<\/h1>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#include <iostream&gt;\n\nusing namespace std;\n\nint solve() {\n    int n;\n    cin &gt;&gt; n;\n    \/\/1\u30012\u9700\u7279\u6b8a\u5904\u7406\n    if (n == 1)\n        return 2;\n    if (n == 2)\n        return 1;\n    \/\/\u8d2a\u5fc3\uff0c\u6700\u540e\u4e00\u6b65\u4e4b\u524d\u5168\u90e8\u8d703\n    int t = n % 3;\n    if (t == 0)\n        return n \/ 3;\n    else\/\/\u5982\u679c\u4f591\u30012\uff0c\u9700\u8981\u8ba9\u524d\u4e00\u6b65\u8d702\uff0c\u518d\u8d70\u4e00\u6b65\uff1a2\u30013\u5230\u8fbe\u76ee\u6807\u70b9\uff1b\n        return n \/ 3 + 1;\n}\n\nint main() {\n    int t;\n    cin &gt;&gt; t;\n    while (t--)\n        cout << solve() << endl;\n}\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #5E81AC; font-weight: bold\">#<\/span><span style=\"color: #81A1C1\">include<\/span><span style=\"color: #5E81AC\"> <\/span><span style=\"color: #ECEFF4\">&lt;<\/span><span style=\"color: #A3BE8C\">iostream<\/span><span style=\"color: #ECEFF4\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">using<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">namespace<\/span><span style=\"color: #D8DEE9FF\"> std<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">solve<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> n<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    cin <\/span><span style=\"color: #81A1C1\">&gt;&gt;<\/span><span style=\"color: #D8DEE9FF\"> n<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">    \/\/1\u30012\u9700\u7279\u6b8a\u5904\u7406<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">n <\/span><span style=\"color: #81A1C1\">==<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">n <\/span><span style=\"color: #81A1C1\">==<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">    \/\/\u8d2a\u5fc3\uff0c\u6700\u540e\u4e00\u6b65\u4e4b\u524d\u5168\u90e8\u8d703<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> t <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> n <\/span><span style=\"color: #81A1C1\">%<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">t <\/span><span style=\"color: #81A1C1\">==<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> n <\/span><span style=\"color: #81A1C1\">\/<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">else<\/span><span style=\"color: #616E88\">\/\/\u5982\u679c\u4f591\u30012\uff0c\u9700\u8981\u8ba9\u524d\u4e00\u6b65\u8d702\uff0c\u518d\u8d70\u4e00\u6b65\uff1a2\u30013\u5230\u8fbe\u76ee\u6807\u70b9\uff1b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> n <\/span><span style=\"color: #81A1C1\">\/<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">main<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> t<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    cin <\/span><span style=\"color: #81A1C1\">&gt;&gt;<\/span><span style=\"color: #D8DEE9FF\"> t<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">while<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">t<\/span><span style=\"color: #81A1C1\">--<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        cout <\/span><span style=\"color: #81A1C1\">&lt;&lt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">solve<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">&lt;&lt;<\/span><span style=\"color: #D8DEE9FF\"> endl<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u6b22\u8fce\u6539\u6b63\u4e0e\u8865\u5145<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u9898\u76ee\uff1a \u4e8c\u3001\u601d\u8def\uff1a \u8fd9\u6bb5\u4ee3\u7801\u7684\u4e3b\u8981\u601d\u8def\u662f\u89e3\u51b3\u4e00\u4e2a\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u4f4d\u7f6e n\uff0c\u8ba1\u7b97\u8fbe\u5230\u8be5\u4f4d\u7f6e\u7684\u6700\u5c0f\u8df3\u8dc3\u6b21\u6570\u3002 \u4ee3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[9,10],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-3","tag-9","tag-10"],"_links":{"self":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74"}],"version-history":[{"count":1,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":76,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions\/76"}],"wp:attachment":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}