HDU 4864 task (more than 2014 schools-Greedy)

Source: Internet
Author: User

Task


The idea was similar at the time of the competition. I felt that I could be able to handle it, and I had to handle it all. I still didn't think about it. Maybe it was a binary error -. -

N machines and M tasks to be completed. Each machine and task has two attributes. The machine is the maximum working time and level, A task is the time and level of work. You can get 500 * (Working Hours) + 2 * (levels) for completing a task. The task completion condition is that the machine's working time meets the task's needs. The level must be greater than or equal to the task level. One machine can only be used once, and one task can only be completed by one machine. You need to select policies to complete more tasks.

Idea: I started to think about greed. I also thought that time was the dominant factor when I was greedy. I had to give priority to it. When I wrote it after the game, I realized it using map.

struct node{    int time, lev;} a[100010], b[100010];int cmp(node a, node b){    if(a.time == b.time)        return a.lev > b.lev;    return a.time > b.time;}map<int, int> M;int n, m;int main(){    while(~scanf("%d%d", &n, &m))    {        for(int i = 0; i < n; ++i)        {            scanf("%d%d", &a[i].time, &a[i].lev);        }        for(int i = 0; i < m; ++i)        {            scanf("%d%d", &b[i].time, &b[i].lev);        }        sort(a, a+n, cmp);        sort(b, b+m, cmp);        M.clear();        int j = 0;        int ans1 = 0;        long long ans2 = 0;        for(int i = 0; i < m; ++i)        {            while(j < n && a[j].time >= b[i].time)            {                M[a[j].lev]++;                ++j;            }            map<int, int>::iterator it = M.lower_bound(b[i].lev);            if(it != M.end())            {               ans1++;               ans2 += 500*b[i].time+2*b[i].lev;               int t = it->first;               M[t]--;               if(M[t] == 0)               {                   M.erase(t);               }            }        }        printf("%d %I64d\n", ans1, ans2);    }    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.