{"id":1207,"date":"2021-05-14T13:34:17","date_gmt":"2021-05-14T05:34:17","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=1207"},"modified":"2021-05-14T13:47:26","modified_gmt":"2021-05-14T05:47:26","slug":"%e8%a3%b4%e5%b1%9e%e5%ae%9a%e7%90%86","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2021\/05\/14\/%e8%a3%b4%e5%b1%9e%e5%ae%9a%e7%90%86\/","title":{"rendered":"\u88f4\u5c5e\u5b9a\u7406"},"content":{"rendered":"<h4>\u88f4\u5c5e\u5b9a\u7406<\/h4>\n<p>\u88f4\u5c5e\u5b9a\u7406\uff0c\u53c8\u53eb\u8d1d\u7956\u5b9a\u7406\u3002\u662f\u4e00\u4e2a\u5173\u4e8e\u6700\u5927\u516c\u7ea6\u6570\u7684\u5b9a\u7406\u3002\u5176\u5185\u5bb9\u4e3a\uff1a\u8bbe<code class=\"katex-inline\">a,b<\/code>\u662f\u4e0d\u5168\u4e3a0\u7684\u6574\u6570\uff0c\u5b58\u5728\u6574\u6570\u89e3<code class=\"katex-inline\">(x,y)<\/code>\uff0c\u4f7f\u5f97<code class=\"katex-inline\">ax + by = gcd(a, b)<\/code>\u3002<br \/>\n\u90a3\u4e48\u5bf9\u4e8e\u65b9\u7a0b<code class=\"katex-inline\">ax + by = c<\/code>\uff0c\u82e5\u4e0d\u6ee1\u8db3<code class=\"katex-inline\">[gcd(a,b)|c]<\/code>\uff0c\u5219\u65b9\u7a0b\u65e0\u89e3\u3002<\/p>\n<p>\u6269\u5c55\u6b27\u51e0\u91cc\u5f97\u5b9a\u7406\u662f\u7528\u6765\u89e3\u8be5\u65b9\u7a0b\u7684\u3002<\/p>\n<p>\u9898\u76ee<\/p>\n<h5><a href=\"http:\/\/codeforces.com\/contest\/512\/problem\/B\">CF512B Fox And Jumping<\/a><\/h5>\n<p>\u9898\u610f\u662f\u7ed9\u5b9an\u7ec4\u6570<code class=\"katex-inline\">(l_i,c_i)<\/code>\uff0c\u5728\u4e00\u4e2a\u65e0\u9650\u5927\u7684\u76f4\u7ebf\u4e0a\uff0c\u6bcf\u9009\u5b9a\u4e00\u7ec4\u6570\uff0c\u4f60\u9700\u8981\u4ed8\u51fa<code class=\"katex-inline\">c_i<\/code>\u7684\u4ee3\u4ef7\uff0c\u4ee5\u540e\u4f60\u53ef\u4ee5\u65e0\u9650\u6b21\u5411\u524d\u6216\u5411\u540e\u8d70<code class=\"katex-inline\">l_i<\/code>\u6b65\uff0c\u4e5f\u53ef\u4ee5\u8d70\u4e4b\u524d\u5df2\u7ecf\u9009\u8fc7\u7684\u6570\uff0c\u95ee\u53ef\u4ee5\u5230\u8fbe\u76f4\u7ebf\u4e0a\u4efb\u610f\u4e00\u70b9\u7684\u6700\u5c0f\u4ee3\u4ef7\u3002\u65e0\u89e3\u8f93\u51fa-1\u3002<\/p>\n<p>\u5206\u6790\uff1a\u5148\u8003\u8651\u4e24\u4e2a\u6570a\uff0cb\uff0c\u5982\u679c\u8981\u6ee1\u8db3\u9898\u610f\u6761\u4ef6\uff0c\u5fc5\u987b\u4f7f\u5f97\u8fd9\u4e24\u4e2a\u6570\u901a\u8fc7\u6570\u6b21\u76f8\u52a0\u6216\u8005\u76f8\u51cf\u4f7f\u5f97\u5176\u7ed3\u679c\u7edd\u5bf9\u503c\u4e3a1\uff0c\u4e5f\u5c31\u662f\u8bf4<code class=\"katex-inline\">ax + by = 1<\/code>\u9700\u8981\u6709\u89e3\uff0c\u518d\u6839\u636e\u88f4\u5c5e\u5b9a\u7406\uff0ca\u548cb\u5fc5\u987b\u6ee1\u8db3\u6761\u4ef6<code class=\"katex-inline\">gcd(a,b)=1<\/code>\u624d\u4f1a\u6709\u89e3\u3002\u90a3\u4e48\u63a8\u5e7f\u5230n\u4e2a\u6570\u7684\u60c5\u51b5\uff0c\u5176\u5b9e\u5c31\u662f\u4ece\u4e2d\u9009\u51fa\u4e00\u4e9b\u6570\u6765\uff0c\u4f7f\u5f97\u5176\u6700\u5927\u516c\u7ea6\u6570\u4e3a1\uff0c\u6c42\u6700\u5c0f\u4ee3\u4ef7\u3002<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u80cc\u5305\u95ee\u9898\uff0c\u8bbemp[i]\u4e3a\u6700\u5c0f\u516c\u7ea6\u6570\u4e3ai\u65f6\u7684\u6700\u5c0f\u4ee3\u4ef7\uff0c\u5e76\u521d\u59cb\u5316mp[0] = 0\uff0c\u7136\u540e\u6bcf\u52a0\u5165\u4e00\u4e2a\u6570\uff0c\u5c31\u8003\u8651\u66f4\u65b0mp\u4e2d\u7684\u6240\u6709\u503c\uff0c\u6700\u540e\u8f93\u51famp[1]\u5373\u53ef\u3002<\/p>\n<pre><code class=\"language-c++\">#include &lt;bits\/stdc++.h&gt;\n\nusing namespace std;\n\nmap&lt;int, int&gt; mp;\n\nint gcd(int a, int b) {\n    return b==0?a:gcd(b, a%b);\n}\nint n;\nint l[303], c[303];\nint main() {\n    cin &gt;&gt; n;\n    for (int i=1; i&lt;=n; i++)    cin &gt;&gt; l[i];\n    for (int i=1; i&lt;=n; i++)    cin &gt;&gt; c[i];\n    map&lt;int, int&gt;::iterator it;\n    mp[0] = 0;\n    for (int i=1; i&lt;=n; i++) {\n        for (it=mp.begin(); it!=mp.end(); it++) {        \/\/\u62ff\u51fa\u4e00\u4e2a\u6700\u5927\u516c\u7ea6\u6570\n            int tmp = it-&gt;first;\n            int d = gcd(tmp, l[i]);\n            if (mp.count(d))    mp[d] = min(mp[d], it-&gt;second + c[i]);      \/\/ \u82e5d\u5df2\u7ecf\u5b58\u5728\uff0c\u8003\u8651\u66f4\u65b0\u5176\u6700\u4f18\u89e3\n            else    mp[d] = it-&gt;second + c[i];        \/\/ \u82e5d\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48\u5c31\u8d4b\u503c\n        }\n    }\n    if (mp.count(1))    cout &lt;&lt; mp[1];\n    else    cout &lt;&lt; &quot;-1&quot;;\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u88f4\u5c5e\u5b9a\u7406 \u88f4\u5c5e\u5b9a\u7406\uff0c\u53c8\u53eb\u8d1d\u7956\u5b9a\u7406\u3002\u662f\u4e00\u4e2a\u5173\u4e8e\u6700\u5927\u516c\u7ea6\u6570\u7684\u5b9a\u7406\u3002\u5176\u5185\u5bb9\u4e3a\uff1a\u8bbea,b\u662f\u4e0d\u5168\u4e3a0\u7684\u6574\u6570\uff0c\u5b58 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[48],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1207"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=1207"}],"version-history":[{"count":5,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1207\/revisions"}],"predecessor-version":[{"id":1212,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1207\/revisions\/1212"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=1207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=1207"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=1207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}