HDU 4864 Task(2014多校--貪心)

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   2014   

Task

 

比賽當時思路想的差不多,感覺能過的,該處理的也都處理到了,最後還是沒過,可能是二分寫錯了吧-。-

大意:給你n個機器,m個要完成的任務,每個機器跟任務都有兩個屬性,機器是最大工作時間跟等級,任務是需要工作的時間跟等級。完成一個任務可以得到500*(工作時間)+2*(等級)的報酬。完成任務的條件是機器的工作時間滿足任務的需要,等級要大於等於任務的等級,一個機器只能用一次,一個任務也只能用一個機器去完成。需要進行策略選擇,使得完成更多的任務。

思路:開始想的就是貪心,也想到了貪心的時候時間是主導因素,要優先考慮,賽後寫的時候是看的標程用的map來實現的。

 

 1 struct node 2 { 3     int time, lev; 4 } a[100010], b[100010]; 5  6 int cmp(node a, node b) 7 { 8     if(a.time == b.time) 9         return a.lev > b.lev;10     return a.time > b.time;11 }12 13 map<int, int> M;14 int n, m;15 16 int main()17 {18     while(~scanf("%d%d", &n, &m))19     {20         for(int i = 0; i < n; ++i)21         {22             scanf("%d%d", &a[i].time, &a[i].lev);23         }24         for(int i = 0; i < m; ++i)25         {26             scanf("%d%d", &b[i].time, &b[i].lev);27         }28         sort(a, a+n, cmp);29         sort(b, b+m, cmp);30         M.clear();31         int j = 0;32         int ans1 = 0;33         long long ans2 = 0;34         for(int i = 0; i < m; ++i)35         {36             while(j < n && a[j].time >= b[i].time)37             {38                 M[a[j].lev]++;39                 ++j;40             }41             map<int, int>::iterator it = M.lower_bound(b[i].lev);42             if(it != M.end())43             {44                ans1++;45                ans2 += 500*b[i].time+2*b[i].lev;46                int t = it->first;47                M[t]--;48                if(M[t] == 0)49                {50                    M.erase(t);51                }52             }53         }54         printf("%d %I64d\n", ans1, ans2);55     }56 57     return 0;58 }
HDU 4864

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.