zoukankan      html  css  js  c++  java
  • 2014多校联盟 第一场 Task 贪心

    问题 D: Task

    题目描述

    Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task’s level yi cannot complete this task. If the company completes this task, they will get (500*xi+2*yi) dollars.
    The company has n machines. Each machine has a maximum working time and a level. If the time for the task is more than the maximum working time of the machine, the machine can not complete this task. Each machine can only complete a task one day. Each task can only be completed by one machine.
    The company hopes to maximize the number of the tasks which they can complete today. If there are multiple solutions, they hopes to make the money maximum.

    输入

    The input contains several test cases.
    The first line contains two integers N and M. N is the number of the machines.M is the number of tasks(1 < =N <= 100000,1<=M<=100000).
    The following N lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the maximum time the machine can work.yi is the level of the machine.
    The following M lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the time we need to complete the task.yi is the level of the task.

    输出

    For each test case, output two integers, the maximum number of the tasks which the company can complete today and the money they will get.

    样例输入

    1 2
    100 3
    100 2
    100 1

    样例输出

    1 50004
    思路: 首先把任务和机器从大到小排序,先排序时间,其次是等级。
    枚举能做完任务A的机器,并挑选时间最短,等级最低的机器。如此类推。

    AC代码:
    #include <cstring>
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    const int maxn = 100005;
    struct t{
        int x, y;
    };
    
    bool cmp(t a, t b){
        if(a.x == b.x) return a.y > b.y;
        return a.x > b.x;
    
    }
    int main()
    {
        int n, m;
        t task[maxn], mach[maxn];
        while(~scanf("%d%d", &n, &m)){
            for(int i = 0; i < n; i++){
                scanf("%d%d", &mach[i].x, &mach[i].y);
            }
            for(int i = 0; i < m; i++){
                scanf("%d%d", &task[i].x, &task[i].y);
            }
    
            sort(mach, mach + n, cmp);
            sort(task, task + m, cmp);
            int temp[maxn];
            memset(temp, 0 ,sizeof(temp));
            int num = 0;
            long long int  money = 0;
            for(int i = 0, j = 0; i < m; i++){
                while(mach[j].x >= task[i].x && j < n){
    
                    temp[mach[j].y]++;
                     j++;
                }
                for(int k = task[i].y; k <= 100; k++){
                    if(temp[k]){
                        temp[k]--;
                        num++;
                        money += task[i].x*500 + task[i].y*2;
                        break;
                    }
                }
            }
            printf("%d %I64d
    ",num, money);
        }
        return 0;
    }
    View Code
     
  • 相关阅读:
    Servlet3.0注解配置访问路径和urlParttern配置
    Servlet生命周期和方法
    Jsoup快速查询
    XML解析——Jsoup解析器
    XML解析
    XML约束
    XML基础——extensible markup language
    不使用注解和使用注解的web-service-dao结构
    注解@Component方式代替xml装配bean
    信息检索中的各项评价指标
  • 原文地址:https://www.cnblogs.com/cshg/p/5651655.html
Copyright © 2011-2022 走看看