{"id":21,"date":"2023-11-29T16:22:06","date_gmt":"2023-11-29T08:22:06","guid":{"rendered":"https:\/\/ablazy.cn\/?p=21"},"modified":"2023-11-29T16:24:33","modified_gmt":"2023-11-29T08:24:33","slug":"%e7%94%b5%e6%a2%af%e8%b0%83%e5%ba%a6%e7%ae%97%e6%b3%95scan","status":"publish","type":"post","link":"https:\/\/ablazy.cn\/index.php\/2023\/11\/29\/%e7%94%b5%e6%a2%af%e8%b0%83%e5%ba%a6%e7%ae%97%e6%b3%95scan\/","title":{"rendered":"\u7535\u68af\u8c03\u5ea6\u7b97\u6cd5(SCAN)"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><p><strong>\u9a71\u52a8\u8c03\u5ea6-\u91c7\u7528\u7535\u68af\u8c03\u5ea6\u7b97\u6cd5\u6392\u5217\u51fa\u78c1\u76d8\u8bf7\u6c42\u54cd\u5e94\u6b21\u5e8f<\/strong><\/p>\n<p><strong>\u9898\u76ee\u63cf\u8ff0\uff1a\u8981\u6c42\u8f93\u5165\u4e00\u4e2a\u67f1\u9762\u8bbf\u95ee\u8bf7\u6c42\u5e8f\u5217\u4ee5\u53ca\u5f53\u524d\u78c1\u5934\u6240\u5728\u67f1\u9762\u53f7\u548c\u79fb\u52a8\u65b9\u5411\uff0c\u8f93\u51fa\u91c7\u7528\u7535\u68af\u8c03\u5ea6\u7b97\u6cd5\u65f6\u79fb\u52a8\u81c2\u54cd\u5e94\u7684\u67f1\u9762\u8bbf\u95ee\u5e8f\u5217<\/strong><\/p>\n<p><strong>\u8f93\u5165\u683c\u5f0f\uff1a<\/strong>\n\u7a0b\u5e8f\u8981\u6c42\u8f93\u51653\u884c\uff0c\u4ee5\u56de\u8f66\u7b26\u53f7\u4f5c\u4e3a\u5206\u9694\n\u7b2c1\u884c\u662f2\u4e2a\u6574\u6570n\u3001m\uff0c\u4e4b\u95f4\u7528\u7a7a\u683c\u9694\u5f00\uff0cn\u8868\u793a\u5f53\u524d\u78c1\u5934\u6240\u5728\u7684\u67f1\u9762\u53f7\uff1bm\u8868\u793a\u7b2c\u4e8c\u884c\u8f93\u5165m\u4e2a\u6570\n\u7b2c2\u884c\u662fm\u4e2a\u6574\u6570\uff0c\u6570\u4e4b\u95f4\u4ee5\u7a7a\u683c\u4f5c\u4e3a\u5206\u9694\uff0c\u8868\u793a\u67f1\u9762\u8bbf\u95ee\u8bf7\u6c42\u5e8f\u5217\n\u7b2c3\u884c\u662f\u6570\u5b57 -1 \u6216 1\uff0c\u5f53\u4e3a -1 \u65f6\u8868\u793a\u79fb\u52a8\u81c2\u5411\u67f1\u9762\u53f7\u51cf\u5c0f\u65b9\u5411\u79fb\u52a8\uff0c\u5f53\u4e3a 1 \u65f6\u8868\u793a\u79fb\u52a8\u81c2\u5411\u67f1\u9762\u53f7\u589e\u5927\u65b9\u5411\u79fb\u52a8<\/p>\n<p><strong>\u8f93\u51fa\u683c\u5f0f\uff1a<\/strong>\n\u8f93\u51fam\u4e2a\u6574\u6570\uff0c\u6570\u4e4b\u95f4\u4ee5\u7a7a\u683c\u4f5c\u4e3a\u5206\u9694\uff0c\u91c7\u7528\u7535\u68af\u8c03\u5ea6\u7b97\u6cd5\u65f6\u79fb\u52a8\u81c2\u54cd\u5e94\u7684\u67f1\u9762\u8bbf\u95ee\u5e8f\u5217\u3002<\/p>\n<h1>\u8bbe\u8ba1\u601d\u8def<\/h1>\n<ol>\n<li>\u5c06\u8981\u8bbf\u95ee\u7684\u67f1\u9762\u53f7\u6392\u597d\u5e8f\uff1b<\/li>\n<li>\u627e\u5230\u5f53\u524d\u78c1\u5934\u6240\u5728\u7684\u67f1\u9762\u53f7\u5728\u5e8f\u5217\u4e2d\u7684\u4f4d\u7f6e\uff1b<\/li>\n<li>\u4ee5\u8fd9\u4e2a\u4f4d\u7f6e\u4e3a\u57fa\u51c6\uff0c\u5bf9\u524d\u534a\u90e8\u5206\u548c\u540e\u534a\u90e8\u5206\u7684\u67f1\u9762\u53f7\u4f9d\u7167\u78c1\u5934\u8bbf\u95ee\u7684\u65b9\u5411\u91cd\u65b0\u6392\u5e8f\u3002<\/li>\n<\/ol>\n<h1>\u4ee3\u7801\u90e8\u5206<\/h1>\n<h2>\u6392\u5e8f\u7b97\u6cd5<\/h2>\n<p>\u4f7f\u7528\u5feb\u901f\u6392\u5e8f<\/p>\n<pre><code class=\"language-C\">int sort(int A[], int k, int m, int d)\t\t\n\/\/A\u662f\u5f85\u6392\u5e8f\u5217\uff1bk\u662f\u5f00\u59cb\u7d22\u5f15\uff1b\n\/\/m\u662f\u7ed3\u675f\u7d22\u5f15\uff1bd\u8868\u793a\u6b63\u5e8f(1)\u8fd8\u662f\u5012\u5e8f(-1)\n{\n\tint i, a;\n\ti = k;\n\ta = d * A[k];\n\tfor (int j = k + 1; j &lt;= m; j++)\n\t{\n\t\tif (d * A[j] &lt;= a)\n\t\t{\n\t\t\ti++;\n\t\t\tif (i != j)\n\t\t\t{\n\t\t\t\tint tmp;\n\t\t\t\ttmp = A[i];\n\t\t\t\tA[i] = A[j];\n\t\t\t\tA[j] = tmp;\n\t\t\t}\n\t\t}\n\t}\n\tint tmp;\n\ttmp = A[k];\n\tA[k] = A[i];\n\tA[i] = tmp;\n\treturn i;\n}\n\nvoid quick_sort(int A[], int k, int m, int d)\n{\n\tif (k &lt; m)\n\t{\n\t\tint i;\n\t\ti = sort(A, k, m, d);\n\t\tquick_sort(A, k, i - 1, d);\n\t\tquick_sort(A, i + 1, m, d);\n\t}\n}\n<\/code><\/pre>\n<h2>SCAN\u7b97\u6cd5<\/h2>\n<pre><code class=\"language-C\">void SCAN(int n, int m, int A[], int d)\t\n\/\/n\u8868\u793a\u5f53\u524d\u78c1\u5934\u6240\u5728\u7684\u67f1\u9762\u53f7\uff1bm\u8868\u793a\u7b2c\u4e8c\u884c\u8f93\u5165m\u4e2a\u6570\n\/\/A\u662f\u8bbf\u95ee\u5e8f\u5217\uff1bd\u662f\u8bbf\u95ee\u65b9\u5411\n{\n\tquick_sort(A, 0, m - 1, -d);\n\tint i;\n\tfor (i = 0; -d*A[i] &lt; -d*n; i++);\n\tquick_sort(A, 0, i-1, d);\n}\n<\/code><\/pre>\n<p>\u5f53<code>d<\/code>\u4e3a-1\u65f6\uff0c\u8981\u6c42\u79fb\u52a8\u81c2\u5411\u67f1\u9762\u53f7\u51cf\u5c0f\u7684\u65b9\u5411\u79fb\u52a8\uff0c\u56e0\u6b64\u5148\u5c06\u5e8f\u5217\u5347\u5e8f\u6392\u5217\uff0c\u518d\u5c06\u524d\u534a\u90e8\u5206\uff08\u6bd4<code>n<\/code>\u5c0f\u7684\u6570\u6309\u7167\u964d\u5e8f\u6392\u5e8f\uff09\u3002\u53cd\u4e4b\uff0c\u5f53<code>d<\/code>\u4e3a1\u65f6\uff0c\u5148\u5c06\u5e8f\u5217\u964d\u5e8f\u6392\u5217\uff0c\u518d\u5c06\u524d\u534a\u90e8\u5206\uff08\u6bd4<code>n<\/code>\u5927\u7684\u6570\u6309\u7167\u5347\u5e8f\u6392\u5e8f\uff09\u3002<\/p>\n<h2>\u4e3b\u7a0b\u5e8f\u90e8\u5206<\/h2>\n<pre><code class=\"language-C\">int main()\n{\t\n\tint n, m;\n\tscanf_s(&quot;%d %d&quot;, &amp;n, &amp;m);\n\tint *A;\n\tA = (int*)malloc(sizeof(int) * m);\n\tfor (int i = 0; i &lt; m; i++)\n\t\tscanf_s(&quot;%d&quot;, &amp;A[i]);\n\tprintf(&quot;\\n&quot;);\n\tint d;\n\tscanf_s(&quot;%d&quot;, &amp;d);\n\tSCAN(n, m, A, d);\n\tfor (int i = 0; i &lt; m; i++)\n\t\tprintf(&quot;%d &quot;, A[i]);\n\treturn 0;\n}\n<\/code><\/pre>\n<h1>\u6d4b\u8bd5\u6837\u4f8b<\/h1>\n<h2>\u6837\u4f8b1\uff1a<\/h2>\n<p><strong>\u8f93\u5165\uff1a<\/strong><\/p>\n<pre><code class=\"language-shell\">15 10\n24 38 2 110 43 36 5 11 6 180  \n-1\n<\/code><\/pre>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre><code class=\"language-shell\">11 6 5 2 24 36 38 43 110 180\n<\/code><\/pre>\n<h2>\u6837\u4f8b2\uff1a<\/h2>\n<p><strong>\u8f93\u5165\uff1a<\/strong><\/p>\n<pre><code class=\"language-shell\">15 10\n24 38 2 110 43 36 5 11 6 180  \n1\n<\/code><\/pre>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre><code class=\"language-shell\">24 36 38 43 110 180 11 6 5 2\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-5"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ablazy.cn\/index.php\/wp-json\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ablazy.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ablazy.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ablazy.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ablazy.cn\/index.php\/wp-json\/wp\/v2\/comments?post=21"}],"version-history":[{"count":2,"href":"https:\/\/ablazy.cn\/index.php\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":23,"href":"https:\/\/ablazy.cn\/index.php\/wp-json\/wp\/v2\/posts\/21\/revisions\/23"}],"wp:attachment":[{"href":"https:\/\/ablazy.cn\/index.php\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ablazy.cn\/index.php\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ablazy.cn\/index.php\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}