周赛时遇到的一道比较有意思的题目: Problem Statement There are N rooms in Maki's new house. The rooms are numbered from 0 to N-1. Some pairs of rooms are connected by bidirectional passages. The passages have the topology of a tree. That is, there are exactly N-…
题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is a solution, there is a solution that uses at most two moves. 最多只有两步 #include <vector> #include <string> #include <list> #include <map&…
从大到小遍历一遍,每次取M个元素,然后求得最小的floor即可 int minimum(int M, vector <int> heights) { sort(heights.begin(),heights.end()); int minFloor = 10000; for(int i = heights.size()-1; i >=M-1; -- i){ int floor = 0; for(int j = 0; j < M; ++j) floor +=heights[i]-he…
比较简单的一题,纠结比较久的是把my_cmp和my_minus放在类中,利用sort函数会出现 no matching function for call to ""sort(std::vector<Interval>::iterator, std::vector<Interval>::iterator, <unresolved overloaded function type>)"" 当把这两个函数放在类外面时就行了 #incl…
注意题目这句话,Once you have each type of candies in a box, you want to pack those boxes into larger boxes, until only one box remains. 两个box合并后必须放入更大一个盒子 题目的有点类似huffman的前部分,此题用堆去做,由于priority_queue是用堆实现的,故可以直接使用 每次从堆中选取最小的两个进行合并即可 #include <iostream> #incl…
这题明明是一个简单的类似约瑟夫环的问题,但是由于细节问题迟迟不能得到正确结果,结果比赛完几分钟才改对..耻辱. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define ll long long using namespace std; #define NN 370000 class Choo…