SRM 504.5 DIV2
2011-05-18 22:14
393 查看
话不多说,直接说解题思路……
250分:
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: Choose the poorest friend. If there are multiple poorest friends, choose one of them randomly. Give 1 dollar to the chosen friend. You are given an int jackpot, the number of dollars John has won, and a vector <int> money, where the i-th element is the number of dollars currently owned by the i-th friend. Return a vector <int> containing the same number of elements as money. The return value must contain the number of dollars owned by each friend after John has performed the above distribution, sorted in non-decreasing order. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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分:
|
相关文章推荐
- 【Topcoder】SRM158 DIV2总结
- topcoder 记录 srm 144 div2
- SRM 504.5(2-1000pt)
- SRM 554 div2
- TC SRM 548 DIV2
- SRM 585 DIV2
- SRM-697-DIV2
- SRM 548 DIV2
- SRM 513 div2
- SRM 504.5
- SRM 504.5
- srm 552 div2
- SRM 574 250 DIV2
- SRM 667 DIV2 OrderOfOperationsDiv2 500-point
- SRM 504.5 DIV2
- SRM 628 DIV2
- SRM 546 div2
- 【TopCoder】SRM152 DIV2总结
- topcoder srm 595 div1
- TopCoder SRM 360 DIV2 500 分题目, 需要排列组合么?需要强力法么?