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的层数排序.在深一层的优先级高.那么就能够贪心了,每次选择层数最深的 ...
随机推荐
- [LeetCode107]Binary Tree Level Order Traversal II 二叉树层次遍历
题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...
- ServiceStack.Hello——跨平台.net REST api服务搭建
ServiceStack.Hello--跨平台.net REST api服务搭建 自己创建: https://github.com/ServiceStack/ServiceStack/wiki/Cre ...
- 你听说过XML吗?
我们每天都会见到各种各样的书,今天我们就来谈一谈有关书籍带给我们学习的启发. 正如上图所看到的,不同的书籍有不同的外观,比如教科书.儿童图书等:而且书也不是随便能够出版的,要有自己文档结构,语义规则. ...
- 【Android基础】listview控件的使用(1)------最简单的listview的使用
listview控件是项目开发中最常用的空间之一,我将慢慢推出关于listview的一系列的文章,先从最简单的,系统自带的listview开始吧! 先上效果图: activity_one.xml &l ...
- 什么时候PHP经验MySQL存储过程
1.MySQL存储过程 数据库语言,我们经常使用的操作SQL语句必须首先编译在运行时.然后运行,存储过程(Stored Procedure)它被设置为完成一个特定的功能SQL报表设置.编译存储在数据库 ...
- Android剪裁图片简单的方法
/** * 按正方形裁切图片 */ public static Bitmap ImageCrop(Bitmap bitmap) { int w = bitmap.getWidth(); // 得到图片 ...
- C该结构变化 struct typedef
这几天看代码,看到若干类型的结构,例如下列结构声明: struct book{ string name; int price; int num; }; 此种结构定义结构变量的格式例如以下: ...
- SenchaTouch2.3.1 正在使用listpaging以及pullrefresh插入 分页演示样品做
实际上本实施例是相对简单的.自定义PullRefreshFn插头继承Ext.plugin.PullRefresh. 主要是其附加refreshFn下拉监控事件. listpaging么改动.再将这两个 ...
- Script:SQL调优健康检查脚本
Script:SQL调优健康检查脚本 http://www.askmaclean.com/archives/sql-tuning-health-check-script.html 以下脚本可以用于收集 ...
- opengl编程指南
第一章 opengl简单介绍 1.1 什么是opengl opengl是图形硬件的一种软件接口. 1>渲染(rendering)是计算机依据模型创建图像的过程. 2>模型(m ...