{"id":1004,"date":"2021-03-11T21:28:42","date_gmt":"2021-03-11T13:28:42","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=1004"},"modified":"2021-04-06T21:15:17","modified_gmt":"2021-04-06T13:15:17","slug":"c%e5%b8%b8%e7%94%a8%e5%ba%93%e5%87%bd%e6%95%b0%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2021\/03\/11\/c%e5%b8%b8%e7%94%a8%e5%ba%93%e5%87%bd%e6%95%b0%e7%94%a8%e6%b3%95\/","title":{"rendered":"C++\u5e38\u7528\u5e93\u51fd\u6570\u7528\u6cd5"},"content":{"rendered":"<h5>\u4f18\u5148\u6743\u961f\u5217<\/h5>\n<pre><code class=\"language-c++\">\/\/ \u4f18\u5148\u6743\u961f\u5217\u9ed8\u8ba4\u662f\u6700\u5c0f\u5806\uff0c\u5373\u5806\u9876\u5143\u7d20\u6700\u5c0f\npriority_queue&lt;int, queue&lt;int&gt;, greater&lt;int&gt;&gt; q;  \/\/\u6700\u5c0f\u5806\uff0c\u5806\u9876\u7684\u5143\u7d20\u503c\u6700\u5c0f\npriority_queue&lt;int, queue&lt;int&gt;, less&lt;int&gt;&gt; q;     \/\/\u6700\u5927\u5806\uff0c\u5806\u9876\u7684\u5143\u7d20\u503c\u6700\u5927\n\n\/\/\u7ed3\u6784\u4f53\u4f18\u5148\u6743\u961f\u5217\u6bd4\u8f83\u7279\u6b8a\uff0c\u53ea\u80fd\u6309\u7167\u4ece\u5927\u5230\u5c0f\u7684\u65b9\u5f0f\u6392\u5217\u7ed3\u6784\u4f53\uff0c\u4f46\u662f\u53ef\u4ee5\u91cd\u8f7d\u7ed3\u6784\u4f53\u7684\u5c0f\u4e8e\u6bd4\u8f83\u8fd0\u7b97\u7b26 &lt;\n\/\/\u53cd\u6b63\u662f\u548c\u91cd\u8f7d\u8fd0\u7b97\u7b26\u91cc\u53cd\u7740\u6765\u7684\ntypedef struct zyh {\n    int x, y;\n}zyh;\nbool operator &lt; (const&amp; a, const&amp; b) {\n    if (a.x != b.x) return a.x &lt; b.x;\n    return a.y &gt; b.y;\n}\npriority_queue&lt;zyh&gt; q;\n\nq.push(zyh{2, 3});\nq.push(zyh{2, 5});\ncout &lt;&lt; (a&lt;b);        \/\/ false  \u56e0\u4e3a &lt;(a, b)\u51fd\u6570\u8fd4\u56de\u7684\u503c\u662ffalse, \u4e5f\u5c31\u662f\u8bf4a\u4e0d\u5c0f\u4e8eb, \u6ce8\u610f\u8fd9\u5e76\u4e0d\u610f\u5473\u7740a&gt;b, \u56e0\u4e3a\u5e76\u6ca1\u6709\u91cd\u8f7d\u7ed3\u6784\u4f53\u7684\u5927\u4e8e\u8fd0\u7b97\u7b26\ncout &lt;&lt; q.top().y;    \/\/ 3\n<\/code><\/pre>\n<h5>sort\u51fd\u6570\u7528\u6cd5<\/h5>\n<pre><code class=\"language-c++\">\/* sort\u51fd\u6570\u7684\u5177\u4f53\u7528\u6cd5\u662f\uff1a *\/\nsort (begin_pos, end_pos, cmp);\n\/* \u529f\u80fd\u662f\u5bf9[begin_pos, end_pos)\u4e4b\u95f4\u7684\u8fde\u7eed\u7684\u540c\u7c7b\u578b\u7684\u5143\u7d20\u6309\u7167cmp\u7684\u65b9\u5f0f\u8fdb\u884c\u6392\u5e8f \u53c2\u6570cmp\u53ef\u7701 *\/\n\n\/\/ \u5bf9\u666e\u901a\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f   [1, 10]\u8303\u56f4\u5185\u6392\u5e8f\nint a[100], n=10;\nsort (a+1, a+n+1);    \/\/\u9ed8\u8ba4\u4e3a\u5347\u5e8f\uff0c\u4ece\u5c0f\u5230\u5927\u6392\n\n\/\/ \u5bf9vector\u8fdb\u884c\u6392\u5e8f\nvector&lt;int&gt; a(3);    \/\/\u5927\u5c0f\u4e3a3\u7684\u6570\u7ec4\nsort (a.begin(), a.end(), greater&lt;int&gt;());     \/\/ \u6309\u4ece\u5927\u5230\u5c0f\u6392\u5e8f\uff0c\u548c\u4f18\u5148\u6743\u961f\u5217\u53cd\u7740\u6765...\nsort (a.begin(), a.end(), less&lt;int&gt;());        \/\/ \u6309\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\n\nbool cmp (const zyh&amp; a, const zyh&amp; b) {\n    return a.x &lt; b.x;\n}\n\nsort (begin, end, cmp);\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f18\u5148\u6743\u961f\u5217 \/\/ \u4f18\u5148\u6743\u961f\u5217\u9ed8\u8ba4\u662f\u6700\u5c0f\u5806\uff0c\u5373\u5806\u9876\u5143\u7d20\u6700\u5c0f priority_queue&lt;int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1004"}],"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=1004"}],"version-history":[{"count":6,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1004\/revisions"}],"predecessor-version":[{"id":1029,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1004\/revisions\/1029"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=1004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=1004"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=1004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}