{"id":3876,"date":"2019-10-03T00:53:57","date_gmt":"2019-10-02T16:53:57","guid":{"rendered":"https:\/\/damogame.cn\/wordpress\/?p=3876"},"modified":"2019-10-03T00:53:57","modified_gmt":"2019-10-02T16:53:57","slug":"%e6%9c%80%e4%bd%b3%e4%ba%a4%e6%98%93","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/3876","title":{"rendered":"\u6700\u4f73\u4ea4\u6613"},"content":{"rendered":"<p>\u77e5\u9053\u6bcf\u65e5\u91d1\u4ef7\uff0c\u5e0c\u671b\u4ece\u4e2d\u627e\u51fa\u4e24\u4e2a\u4ea4\u6613\u65e5\uff0c\u5728\u7b2c\u4e00\u4e2a\u4ea4\u6613\u65e5\u4e70\u8fdb\uff0c\u7b2c\u4e8c\u4e2a\u4ea4\u6613\u65e5\u5356\u51fa\uff0c\u80fd\u5b9e\u73b0\u5229\u6da6\u6700\u5927\u5316\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#include \"pch.h\"\r\n#include &lt;iostream&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;time.h&gt;\r\n\r\nconst size_t INVALID_POS = -1;\r\n\r\nstd::pair&lt;size_t, size_t&gt; GetTradePos(const std::vector&lt;int&gt;&amp; prices) {\r\n    if (prices.size() &lt; 2) {\r\n        \/\/\u4e2a\u6570\u5c0f\u4e8e2\uff0c\u627e\u4e0d\u51fa\u4e70\u5356\u70b9\r\n        return std::make_pair(INVALID_POS, INVALID_POS);\r\n    }\r\n    else if (prices.size() == 2) {\r\n        if (prices[0] &gt;= prices[1]) {\r\n            \/\/\u6ca1\u6709\u5229\u6da6\uff0c\u627e\u4e0d\u51fa\u4e70\u5356\u70b9\r\n            return std::make_pair(INVALID_POS, INVALID_POS);\r\n        }\r\n        else {\r\n            return std::make_pair(0, 1);\r\n        }\r\n    }\r\n\r\n    int max_gain = 0;\r\n    int buy_pos = INVALID_POS;\r\n    int sell_pos = INVALID_POS;\r\n    for (int i = 0; i &lt; prices.size() - 1; i++) {\r\n        for (int j = i + 1; j &lt; prices.size(); j++) {\r\n            if (prices[j] - prices[i] &gt; max_gain) {\r\n                max_gain = prices[j] - prices[i];\r\n                buy_pos = i;\r\n                sell_pos = j;\r\n            }\r\n        }\r\n    }\r\n\r\n    return std::make_pair(buy_pos, sell_pos);\r\n}\r\n\r\nint main()\r\n{\r\n    std::vector&lt;int&gt; prices;\r\n    srand(time(nullptr));\r\n\r\n    for (int i = 0; i &lt; 50; i++) {\r\n        int rand_num = rand();\r\n        prices.push_back(rand_num);\r\n    }\r\n\r\n    auto ret = GetTradePos(prices);\r\n    return 0;\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u77e5\u9053\u6bcf\u65e5\u91d1\u4ef7\uff0c\u5e0c\u671b\u4ece\u4e2d\u627e\u51fa\u4e24\u4e2a\u4ea4\u6613\u65e5\uff0c\u5728<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[119],"class_list":["post-3876","post","type-post","status-publish","format-standard","hentry","tag-03-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/3876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=3876"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/3876\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=3876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=3876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=3876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}