hdu 4864 Task(贪婪啊)
主题链接: pid=4864">http://acm.hdu.edu.cn/showproblem.php?pid=4864
Task
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 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
基本思想是贪心:
对于价值c=500*xi+2*yi,yi最大影响100*2<500,所以就是求xi总和最大。
能够先对机器和任务的时间从大到小排序。从最大时间的任务開始。找出满足任务时间要求的全部机器。从中找出等级最低且满足任务等级要求的机器匹配。依次对任务寻找满足要求的机器。
代码例如以下:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100017;
struct work
{
int x,y;
}ma[N],ta[N];
bool cmp(work a, work b)
{
if(a.x == b.x)
return a.y > b.y;
return a.x > b.x;
}
int main()
{
int n, m;
int i, j;
int c[N];
while(~scanf("%d%d",&n,&m))
{
memset(c,0,sizeof(c));
for(i = 1; i <= n; i++)
{
scanf("%d%d",&ma[i].x,&ma[i].y);
}
for(i = 1; i <= m; i++)
{
scanf("%d%d",&ta[i].x,&ta[i].y);
}
sort(ma+1,ma+n+1,cmp);
sort(ta+1,ta+m+1,cmp);
int l = 1;
__int64 ans = 0;
int num = 0;
for(i = 1; i <= m; i++)
{
while(l <= n&&ma[l].x >= ta[i].x)
{//寻找全部的能完毕当前任务的机器
c[ma[l].y]++;
l++;
}
for(j = ta[i].y; j <= 100; j++)
{//寻找全部能完毕当前任务的机器中等级最低的
if(c[j])
{
num++;
ans+=500*ta[i].x+2*ta[i].y;
c[j]--;
break;
}
}
}
printf("%d %I64d\n",num,ans);
}
return 0;
}
版权声明:本文博主原创文章。博客,未经同意不得转载。
hdu 4864 Task(贪婪啊)的更多相关文章
- HDU 4864 Task(贪心)
HDU 4864 Task 题目链接 题意:有一些机器和一些任务.都有时间和等级,机器能做任务的条件为时间等级都大于等于任务.而且一个任务仅仅能被一个机器做.如今求最大能完毕任务.而且保证金钱尽量多 ...
- Hdu 4864(Task 贪心)(Java实现)
Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...
- hdu 4864 Task
题目链接:hdu 4864 其实就是个贪心,只是当初我想的有偏差,贪心的思路不对,应该是这样子的: 因为 xi 的权值更重,所以优先按照 x 来排序,而这样的排序方式决定了在满足任务(即 xi > ...
- HDU 4864 Task(经典贪心)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=4864 Task Time Limit: 4000/2000 MS (Java/Others) M ...
- HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...
- hdu 4864 Task(贪心)
pid=4864">http://acm.hdu.edu.cn/showproblem.php?pid=4864 大致题意:有n台机器和m个任务,都有两个參数工作时间time和难度le ...
- 2014多校第一场D题 || HDU 4864 Task (贪心)
题目链接 题意 : 用N台机器,M个任务,每台机器都有一个最大工作时间和等级,每个任务有一个需要工作时间和一个等级.如果机器完成一个任务要求是:机器的工作时间要大于等于任务的时间,机器的等级要大于等于 ...
- hdu 4864 Task (贪心 技巧)
题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...
- HDU 4864 Task (贪心)
Task 题目链接: http://acm.hust.edu.cn/vjudge/contest/121336#problem/B Description Today the company has ...
随机推荐
- Lua基础(转)
局部定义与代码块: 使用local声明一个局部变量或局部函数,局部对象只在被声明的那个代码块中有效. 代码块:一个控制结构.一个函数体.一个chunk(一个文件或文本串)(Lua把chunk当做函数处 ...
- DataGridView绑定数据源
给DataGridView绑定数据源比較简单,方法主要有两种: 1.直接在控件属性中绑定数据源,这样的方法最简单,但它是直接连接数据库的,这样就和传DataTable的后果差点儿相同了,所以还是尽量避 ...
- 解决Fedora升级时nvidia显卡问题
升级到新版Fedora后登录不了gnome 小编最近升级了Fedora 20到21,结果就如之前从Fedora 19升级到20时类似,又出问题了.Fedora你到底行不行... gnome登录不了 ...
- Uncaught TypeError: Cannot read property 'call' of undefined jquery.validate.min.js:28
最近在做表单验证时,,自己写的addMethod 方法总是不起作用.折腾了将近一天. 报告的错误,如下面的 Uncaught TypeError: Cannot read property 'call ...
- Codeforces 451E Devu and Flowers(容斥原理)
题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...
- 从苹果系统InstallESD.dmg里提取IOS
右键下载的Mac OS X Mountain Lion镜像:InstallESD.dmg,选择7-zip------打开压缩包 2.双击InstallMacOSX.pkg 3.选中InstallESD ...
- c++ 学籍管理系统v 1.0
#include<iostream> #include <string> #include<conio.h> using namespace std; class ...
- 【软件使用技巧】PL/SQL Developer实现双击table询
二手plsql都知道,在表名默认双击[开展/关闭]. 习惯了MySql Workbench要么Sqlserver Management Studio无法适应其他管理工具. 直接在溶液: Tools - ...
- SQL Server中TempDB管理(版本存储区的一个example)
原文:SQL Server中TempDB管理(版本存储区的一个example) 原文来自: http://blogs.msdn.com/b/sqlserverstorageengine/archive ...
- 移动端 iphone touchmove滑到边界(浏览器地址拦及以上) touchend失效解决办法
在移动端h5页面:尤其那些全屏幕的盒展示切换页面,当用户无意中将手指滑到了 浏览器地址拦以上(中国移动这快区域):此时,手指已经离开屏幕了,但是ios上无法监听到touchend 事件:touchen ...