首页 > 代码库 > hdu4864Task(贪心)
hdu4864Task(贪心)
题目链接:
啊哈哈,点我
题目:
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.
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.
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
2014 Multi-University Training Contest 1
Recommend
We have carefully selected several similar problems for you: 4881 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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。