Leetcode-1086 high five(前五科的均分)

 1 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 2 struct cmp
 3 {
 4     bool operator() (int a,int b)
 5     {
 6         return a>b;
 7     }
 8 };
 9 class Solution
10 {
11     public:
12         vector<vector<int>> highFive(vector<vector<int>>& items)
13         {
14             vector<priority_queue<int,vector<int>,cmp>> v(1002);
15             _for(i,0,items.size())
16             {
17                 if(v[items[i][0]].size() < 5)
18                 {
19                     v[items[i][0]].push(items[i][1]);
20                 }
21                 else
22                 {
23                     if(items[i][1] > v[items[i][0]].top())
24                     {
25                         v[items[i][0]].pop();
26                         v[items[i][0]].push(items[i][1]);
27                     }
28                 }
29             }
30             vector<vector<int>> rnt;
31             _for(i,0,1001)
32             {
33                 if(v[i].size()==5)
34                 {
35                     int sum = 0;
36                     while(v[i].size())
37                     {
38                         sum += v[i].top();
39                         v[i].pop();
40                     }
41                     vector<int> tmp;
42                     tmp.push_back(i);
43                     tmp.push_back(sum/5);
44                     rnt.push_back(tmp);
45                 }
46             }
47             return rnt;
48         }
49 };

 

posted @ 2019-06-16 00:05  Asurudo  阅读(750)  评论(0编辑  收藏  举报