hdu4864Task(馋)
主题链接:
题目:
Task
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2512 Accepted Submission(s): 643
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 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.
1 2
100 3
100 2
100 1
1 50004
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(馋)的更多相关文章
- CF(437C)The Child and Toy(馋)
意甲冠军:给定一个无向图,每个小点右键.操作被拉动所有点逐一将去,直到一个点的其余部分,在连边和点拉远了点,在该点右点的其余的费用.寻找所需要的最低成本的运营完全成本. 解法:贪心的思想,每次将剩余点 ...
- Codeforces Round #253 DIV1 C 馋
http://codeforces.com/contest/442/problem/C 题意非常easy,基本上肯定有坑坑洼洼的样子.看题目案例,从第三个跟第二个没有凹的案例来看的话,多写几个以及多画 ...
- 非洲儿童(南阳oj1036)(馋)
非洲小孩 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 家住非洲的小孩,都非常黑.为什么呢? 第一.他们地处热带,太阳辐射严重. 第二,他们不常常洗澡.(常年缺水, ...
- Codeforces 549G. Happy Line 馋
非常有趣的贪婪: Let's reformulate the condition in terms of a certain height the towers, which will be on t ...
- BZOJ 1150 CTSC2007 数据备份Backup 堆+馋
标题效果:给定一个长度n−1n-1的序列,要求选出kk个不相邻的数使得和最小 费用流显然能跑.并且显然过不去- - 考虑用堆模拟费用流 一个错误的贪心是每次取最小.这样显然过不去例子 我们把[每次取最 ...
- hdu1052 Tian Ji -- The Horse Racing 馋
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1052">http://acm.hdu.edu.cn/showproblem.php ...
- 懒与馋的平衡:餐饮O2O市场广阔,发展不易
餐饮行业是众多行业中O2O起步较早的,现在方兴未艾的团购站点中最先涉足的领域就有餐饮版块.长时间的合作推广,很多餐饮商家已经从中尝到甜头,可以说餐饮行业市场基础培育的比較好,所以餐饮O2O 已经是大势 ...
- hdu 4864 Task (馋)
# include <stdio.h> # include <algorithm> # include <string.h> using namespace std ...
- hdu 4912 Paths on the tree(lca+馋)
意甲冠军:它使树m路径,当被问及选择尽可能多的路径,而这些路径不相交. 思考:贪心,比較忧伤.首先求一下每对路径的lca.依照lca的层数排序.在深一层的优先级高.那么就能够贪心了,每次选择层数最深的 ...
随机推荐
- ContentProvider的使用
这方面的资料应该网上已经很多了,我在这里只是做简单的总结就行了. 如题:ContentProvider是android的内容提供器,可以为应用程序提供各种的数据,例如数据表,txt文件,xml文件等等 ...
- Linux - SVN下载项目
SVN下载项目 本文地址:http://blog.csdn.net/caroline_wendy 使用SVN.在Git上下载项目. $ mkdir chunyu_trunk //创建目录 $ ls / ...
- effective c++ 条款8 prevent exception from leaving destructor
1 析构函数绝对不要吐出异常.如果一个析构函数可能调用产生异常的函数,析构函数应该不传播该异常或结束程序 2 如果客户需要对某个操作函数运行期间抛出的异常做出反应,那么class应该提供一个普通函数执 ...
- android 他们定义对话框
创建一个布局文件 my_dialog.xml <?xml version="1.0" encoding="utf-8"?> <Relative ...
- RSA算法加密解密
该工具类中用到了BASE64,需要借助第三方类库:javabase64-1.3.1. jar 注意:RSA加密明文最大长度117字节,解密要求密文最大长度为128字节,所以在加密和解密的过程中需要分块 ...
- Minimum Sum LCM(uva10791+和最小的LCM+推理)
L - Minimum Sum LCM Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- linux学习(一个) 在unbuntu通过添加新的用户
最近安装了双系统,开始折腾unbuntu该.Linux系统是一个多用户操作系统,非常多的人才完整的操作需要管理员权限,完全管理员权限是非常重要的.人谁是刚开始学习,般用户的权限即可了,相对于刚開始学习 ...
- dispatch_once认识分析
dispatch_once为了确保代码运行一次 +(NSDateFormatter*)getDBDateFormat { static NSDateFormatter* format; static ...
- c# serialport读取不限数量的16进制数据
//private char[] HexChar = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', ' ...
- 何时使用SET和SELECT为变量赋值
原文:何时使用SET和SELECT为变量赋值 我们经常使用SET和SELECT来为变量复制,但是有时候,只能选其一来使用,下面来看看这些例子,本例中使用AdventureWorks数据库来做演示. 通 ...