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的层数排序.在深一层的优先级高.那么就能够贪心了,每次选择层数最深的 ...
随机推荐
- java实现大数相加问题
闲来没事.写了个acm中常常遇到的大数加减问题的java 解决代码,我想说.用java的BigInteger 非常easy. 大爱java!! 比如: 实现多组输入的大数加减问题: import ja ...
- 机械革命X5(MECHREVO MR-X5)开包检验
不废话.直接的问题,左右X5没有更具体的信息.为了通过有机会了解后续的选择,具体的数据被释放约: 首先看包装: 1.快递包裹,基于卖方这可以是不同的,包装各不相同 watermark/2/text/a ...
- 《炉石传说》建筑设计欣赏(6):卡&在执行数据时,组织能力
上一篇文章我们看到了<炉石传说>核心存储卡的数据,今天,我们不断探索卡&身手. 基本的类 通过之前的分析,卡牌&技能涉及到几个类体系:Entity.Actor.Card.S ...
- Agile/CMMI/Scrum
Agile/CMMI/Scrum 一.背景介绍 在朋友(aehyok)的建议下,初步去了解Visual Studio Online,简称VS Online(即原来的 Team Foundation S ...
- Android开发经验—不要指望类finalize干活的方法做你想要什么
之所以专门写了一篇文章finalize方法博客,这是通过在坑的方法引起的.一个读写jni当数据类.我在课堂上finalize该方法被调用来关闭文件和释放内存的方法.频繁调用这个类的时候在JNI里面报异 ...
- LeetCode Solutions : Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
- MVC 01
ASP.NET MVC 01 - ASP.NET概述 本篇目录: ASP.NET 概述 .NET Framework 与 ASP.NET ASP.NET MVC简介 ASP.NET的特色和优势 典型案 ...
- [Cocos2d-x]在Cocos2d-x 3.x如何通过版本号WebSocket连接server数据的传输
WebSocket 首先新建一个空的目录,通过npm安装nodejs-websocket: npm install nodejs-websocket 新建app.js文件: var ws = requ ...
- 避免内存重叠memmove()性能
#include <iostream> #include <string.h> using namespace std; void* memmove(void *dst, co ...
- Html5响应式设计与实现广场
由于提出的想法响应式设计,越来越多的网站使用这样的思想.各类大型网站如雨后春笋般涌了出来.例如:小米商城.天猫等. 至于响应式设计的概念等大家能够去百度百度,我这里就不相信解说了.直接为大家带来源代码 ...