话不多说,直接说解题思路……
250分:
Problem Statement | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
John has recently won a jackpot, but he doesn't need the money. He decided to share it with his friends instead. He knows how much money each of his friends has, and he will use this information to perform the distribution. While he still has money left, he will repeat the following steps:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Definition | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constraints | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- | money will contain between 1 and 47 elements, inclusive. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- | Each element of money will be between 1 and 1,000,000, inclusive. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- | jackpot will be between 1 and 1,000,000, inclusive. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Examples | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
解题思路: 这道题比较简单,直接就是使用一个优先队列来每次取出一个最小值,然后加上1,不过这个时间可能耗费比较大,但是TC一般不计较时间,只要可以过测试数据就行了。 下面贴上代码: // BEGIN CUT HERE // END CUT HERE #line 5 "TheJackpotDivTwo.cpp" #include <string> #include <vector> #include <queue> using namespace std; class cmp { public: bool operator()(const int &a,const int &b) const { return a>b; } }; class TheJackpotDivTwo { public: vector <int> find(vector <int> money, int jackpot) { priority_queue <int,vector<int>,cmp> pq; int i; if(pq.size()==1) { vector<int>t; t.push_back(money[0]+jackpot); return t; } for(i=0;i<money.size();i++) pq.push(money[i]); int a; int n=jackpot; while(n>0) { a=pq.top(); pq.pop(); pq.push(a+1); n--; } vector<int> ans; while(!pq.empty()) { ans.push_back(pq.top()); pq.pop(); } return ans; } }; 500分:
|