![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
贪心算法
ethannotlazy
这个作者很懒,什么都没留下…
展开
-
1067 Sort with Swap(0, i) (25分)
注意不要暴力查找还没排序的value。 #include<iostream> #include<unordered_map> using namespace std; unordered_map<int, int> indexes; int unsortedNum = 1; int getUnsortedValue() { //don't traverse f...原创 2020-05-05 17:48:47 · 124 阅读 · 0 评论 -
1125 Chain the Ropes (25分)
贪心算法,每次从所有绳子中选两根最短的做成一根绳子,注意将做好的绳子放回容器中。 #include<cstdio> #include<queue> #include<cmath> #include<vector> using namespace std; struct cmp { bool operator () (double a, doub...原创 2020-02-03 10:49:06 · 93 阅读 · 0 评论 -
1033 To Fill or Not to Fill (25分)
先手动模拟一下算法的流程,可以将走法总结如下(贪心算法): 如果到达范围内有比当前站更便宜的站,则加油加到刚好能到那个站。 如果到达范围内没有比当前站更便宜的站,那么将油加满,并且选择到达范围内最便宜(但是比当前站贵)的站。 #include<cstdio> #include<algorithm> using namespace std; struct node {...原创 2020-01-08 14:11:53 · 99 阅读 · 0 评论