話不多說,直接說解題思路……
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分:
|