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\n",num, money);
    }
    return 0;
}

 
时间: 2024-12-28 21:28:56

2014多校联盟 第一场 Task 贪心的相关文章

hdu5289||2015多校联合第一场1002贪心+RMQ

http://acm.hdu.edu.cn/showproblem.php?pid=5289 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to

2014多校联合第一场

1001:Couple doubi 暴力打表找规律可知,对于任意的p. (1^i+2^i+...+(p-1)^i)%p={ 非0     ,i%(p-1)==0 0        ,  i%(p-1)!=0 } 所以,结果就很显然了. #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<c

hdu 4865 Peter&amp;#39;s Hobby(2014 多校联合第一场 E)

Peter's Hobby Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 545    Accepted Submission(s): 237 Problem Description Recently, Peter likes to measure the humidity of leaves. He recorded a leaf

hdu 4865 Peter&#39;s Hobby(2014 多校联合第一场 E)

题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2.给定n天的叶子湿度状态,求这n天最可能的天气情况 分析:概率dp设 dp[i][j] 表示第i天天气为j的最大概率,pre[i][j]表示第i天天气最可能为j的前一天天气,dp[i][j]=max(dp[i-1][k]+log(wePro[k][j])+log(lePro[j][lePos[i]]

hdu 4869 Turn the pokers (2014多校联合第一场 I)

Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1265    Accepted Submission(s): 465 Problem Description During summer vacation,Alice stay at home for a long time, with nothing t

hdu 4865 Peter&#39;s Hobby(2014 多校联合第一场 E)

Peter's Hobby Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 545    Accepted Submission(s): 237 Problem Description Recently, Peter likes to measure the humidity of leaves. He recorded a leaf

2014 多校赛 第一场

题目链接 A - Couple doubi 题意:桌上共有 k 个球,第i个球的值为 (1^i+2^i+...+(p-1)^i )mod p DouBiXp 和 他的女朋友 DouBiNan 轮流拿球,DouBiNan先拿, 所有的球都拿完后,谁手上球的值总和更大谁就赢, 已知 k,p,且p为素数, 若DouBiNan赢输出"YES",否则输出"NO" 分析:DouBiNan先拿,为了赢肯定先拿没有被拿的球中值最大的, 找规律得 每个球的值要么为 0,要么为某个的正

HDU 4870 Rating (2014 多校联合第一场 J)(概率)

题意: 一个人有两个TC的账号,一开始两个账号rating都是0,然后每次它会选择里面rating较小的一个账号去打比赛,每次比赛有p的概率+1分,有1-p的概率-2分,当然如果本身是<=2分的也就还是回到0分.然后问最后其中一个账号到达20分时需要打多少次比赛. 思路: 因为每次50分,到达1000分,所以可以看做每次1分,到达20分dp[i]表示i到20的数学期望那么dp[i] = dp[i+1]*p+dp[i-2]*q+1;令t[i] = dp[i+1]-dp[i]则t[i] = (t[i

HDU 4869 Turn the pokers (2014 多校联合第一场 I)

HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次翻牌后牌的朝向有多少种情况.我们可以把正面朝上理解为1,反面朝上理解为0,那么可以理解为求01串的不同的组合方式有几种. 解题思路:我们可以知道,每张牌假设起始状态都为0,如果翻奇数次,该牌最后的情况是1,如果翻偶数次,该牌的最后情况为0.根据n次翻牌的个数找出1的个数的下限和上限,然后再在这个范围