主题链接:

啊哈哈。点我

题目:

Task

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2512    Accepted Submission(s): 643

Problem Description
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.
 
Input
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.
 
Output
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.
 
Sample Input
1 2
100 3
100 2
100 1
 
Sample Output
1 50004
 
Author
FZU
 
Source
 
Recommend
We have carefully selected several similar problems for you:  4881 

pid=4880" target="_blank" style="color:rgb(26,92,200); text-decoration:none">4880 4879 4878 4877 

思路:

首先考虑获得的酬劳。。500*xi+2*yi,所以yi能够当做次要因素,主观因素是时间。所以对任务。和机器的时间大- >小,等级大->小排序。。

接下来就是枚举,将全部满足机器执行时间》=任务时间的增加数组。然后选满足完毕任务的最小等级的机器去完毕任务。

这种巧妙之处在于后面的加进来的任务必然能够被先前加进来的机所完毕。由于任务是按时间降序排列的。。

那样这道题就得到了完美的解决。。

代码为:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn=100000+10;
int level[100+10];
int n,m,sum;
__int64 ans; struct P
{
int xi,yi;
}machine[maxn],task[maxn]; bool cmp(P a,P b)
{
if(a.xi==b.xi) return a.yi>b.yi;
return a.xi>b.xi;
} void read_data()
{
for(int i=1;i<=n;i++)
scanf("%d%d",&machine[i].xi,&machine[i].yi);
for(int i=1;i<=m;i++)
scanf("%d%d",&task[i].xi,&task[i].yi);
sort(task+1,task+1+m,cmp);
sort(machine+1,machine+1+n,cmp);
} int main()
{
while(~scanf("%d%d",&n,&m))
{
ans=sum=0;
read_data();
memset(level,0,sizeof(level));
for(int i=1,j=1;i<=m;i++)
{
while(j<=n&&machine[j].xi>=task[i].xi)
{
level[machine[j].yi]++;
j++;
}
for(int k=task[i].yi;k<=100;k++)
{
if(level[k])
{
level[k]--;
ans=ans+500*task[i].xi+2*task[i].yi;
sum++;
break;
}
}
}
printf("%d %I64d\n",sum,ans);
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

hdu4864Task(馋)的更多相关文章

  1. CF(437C)The Child and Toy(馋)

    意甲冠军:给定一个无向图,每个小点右键.操作被拉动所有点逐一将去,直到一个点的其余部分,在连边和点拉远了点,在该点右点的其余的费用.寻找所需要的最低成本的运营完全成本. 解法:贪心的思想,每次将剩余点 ...

  2. Codeforces Round #253 DIV1 C 馋

    http://codeforces.com/contest/442/problem/C 题意非常easy,基本上肯定有坑坑洼洼的样子.看题目案例,从第三个跟第二个没有凹的案例来看的话,多写几个以及多画 ...

  3. 非洲儿童(南阳oj1036)(馋)

    非洲小孩 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 家住非洲的小孩,都非常黑.为什么呢? 第一.他们地处热带,太阳辐射严重. 第二,他们不常常洗澡.(常年缺水, ...

  4. Codeforces 549G. Happy Line 馋

    非常有趣的贪婪: Let's reformulate the condition in terms of a certain height the towers, which will be on t ...

  5. BZOJ 1150 CTSC2007 数据备份Backup 堆+馋

    标题效果:给定一个长度n−1n-1的序列,要求选出kk个不相邻的数使得和最小 费用流显然能跑.并且显然过不去- - 考虑用堆模拟费用流 一个错误的贪心是每次取最小.这样显然过不去例子 我们把[每次取最 ...

  6. hdu1052 Tian Ji -- The Horse Racing 馋

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1052">http://acm.hdu.edu.cn/showproblem.php ...

  7. 懒与馋的平衡:餐饮O2O市场广阔,发展不易

    餐饮行业是众多行业中O2O起步较早的,现在方兴未艾的团购站点中最先涉足的领域就有餐饮版块.长时间的合作推广,很多餐饮商家已经从中尝到甜头,可以说餐饮行业市场基础培育的比較好,所以餐饮O2O 已经是大势 ...

  8. hdu 4864 Task (馋)

    # include <stdio.h> # include <algorithm> # include <string.h> using namespace std ...

  9. hdu 4912 Paths on the tree(lca+馋)

    意甲冠军:它使树m路径,当被问及选择尽可能多的路径,而这些路径不相交. 思考:贪心,比較忧伤.首先求一下每对路径的lca.依照lca的层数排序.在深一层的优先级高.那么就能够贪心了,每次选择层数最深的 ...

随机推荐

  1. hadoop-1.1.2 在Windows环境下的部署

    1:先安装Cygwin 参考http://blog.csdn.net/wind520/article/details/9223003 2:下载 3:解压在C:\cygwin\hadoop1 4:配置 ...

  2. C#Process执行批处理后如何获取返回值?

    代码如下   p.StartInfo = new System.Diagnostics.ProcessStartInfo(path, pwd); p.Start();其中path是个BAT的路径!我想 ...

  3. 【原创】用Python爬取LeetCode的AC代码到Github

    在leetCode写了105道题高调膜科,考虑搬迁到自己的GitHub上,做成一个解题题库,面试的时候也可以秀一个 但是!但是! leetCode在线IDE的功能不要太舒服,我直接线上A了不少题,本地 ...

  4. BZOJ 2006 NOI2010 超级钢琴 划分树+堆

    题目大意:给定一个序列.找到k个长度在[l,r]之间的序列.使得和最大 暴力O(n^2logn),肯定过不去 看到这题的第一眼我OTZ了一下午... 后来研究了非常久别人的题解才弄明确怎么回事...蒟 ...

  5. myEclipse勿删文件怎么恢复

    今天码代码的时候项目里有一个jsp文件不小心被删了,又懒得重写,然后发现myEclipse竟然可以恢复被勿删的文件,当然,也仅仅限于最近被删的文件. 具体怎么恢复呢?-------右键点击被删文件所在 ...

  6. 使用Emacs muse制作幻灯片

    PPT太受欢迎.总是必要的交流会议.我看到一个很酷javascript实现,取代PPT. 不过还是很喜欢Emacs要做的事,即使文件难听点. 现在,用muse slidy, 一大区别. 简单的说mus ...

  7. JAVA字符串格式化-String.format()使用

    传统型格类型 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象. 熟悉C语言的同学应该记得C语言的sprintf()方法.两者有类似之处.format()方法有两种重载 ...

  8. uva10341 - solve it (二分查找)

    题目:uva10341-solve it 题目大意:求解给定的方程式解题思路:由于这个方程式在给定的x的范围内是单调递减的.所以能够用二分查找来尝试x的值.这里的 x是要求保留4小数,所以当区间缩小到 ...

  9. Linux/UNIX数据文件和信息系统

    数据文件和信息系统 密码文件 在存储/etc/passwd在.以下功能可以用来获得密码文件条目. #include <sys/types.h> #include <pwd.h> ...

  10. SICP-2锻炼.34

    [锻炼2.34] 为x给定值,找到一个多项式x的值,它也可以被形式化为累积. 下多项式的值: an*x^n + an-1*x^n-1 + .... + a1*x + a0 採用著名的Horner规则, ...