w****x 发帖数: 2483 | 1 //Print All different Combinations of a Number as a Sum of Candidate Numbers
//Before start coding, several things to consider
//1. How to deal with duplicated numbers (sort them)
//2. What exactly is the successful ending condition
//3. What exactly is the failure ending condition
//4. For the container, pass by reference or by value
void _inner_print(int a[], int n, int nSum, vector& vecRes)
{
//the success ending condition is nSum == 0 and at the
//same time n == 0!! not nSum == ... 阅读全帖 |
|
w****x 发帖数: 2483 | 2 int getHandlerId(Request request);
Handler getHandler(int id);
vector getResponse( vector requests)
{
map> mp;
for (vector::iterator it = requests.begin();
it != requests.end(); it++)
{
int nh = getHandlerId(*it);
if (mp.find(nh) == mp.end())
{
vector vec;
mp[nh] = vec;
}
mp[nh].push_back(*it);
}
vector vecRes;
map rrMp;
for (map>::iterator it = m... 阅读全帖 |
|
w****x 发帖数: 2483 | 3 随手写了一个,没测
class CMinHeap
{
public:
int GetSize() { return m_vec.size(); }
bool empty() { return m_vec.empty(); }
int top() { return m_vec[0]; }
void pop()
{
swap(m_vec[0], m_vec[m_vec.size()-1]);
m_vec.pop_back();
int nCur = 0;
while (2*nCur+1 < m_vec.size())
{
int nSwap = 2*nCur+1;
if (2*nCur+2 < m_vec.size() && m_vec[2*nCur+2] < m_vec[2*nCur+1])
nSwap = 2*nCur+2;
if (m_ve... 阅读全帖 |
|
w****x 发帖数: 2483 | 4 随手写了一个,没测
class CMinHeap
{
public:
int GetSize() { return m_vec.size(); }
bool empty() { return m_vec.empty(); }
int top() { return m_vec[0]; }
void pop()
{
swap(m_vec[0], m_vec[m_vec.size()-1]);
m_vec.pop_back();
int nCur = 0;
while (2*nCur+1 < m_vec.size())
{
int nSwap = 2*nCur+1;
if (2*nCur+2 < m_vec.size() && m_vec[2*nCur+2] < m_vec[2*nCur+1])
nSwap = 2*nCur+2;
if (m_ve... 阅读全帖 |
|