HDU4864_Task_贪心
来源:互联网 发布:傲剑双龙斩升级数据 编辑:程序博客网 时间:2024/06/06 19:04
Task
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6721 Accepted Submission(s): 1786
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 2100 3100 2100 1
Sample Output
1 50004
公司有不同类型的任务和不同类型的机器。任务和机器都有两个属性,时长和等级。只有机器的时长和等级都大于等于一项任务,机器才能完成这项任务。并且,一项任务只能由一台机器完成,一台机器只能完成一项任务。每完成一项任务的利润为 (500*xi+2*yi) 其中 xi yi 分别是任务的时间和等级。求完成任务的策略,使总利润最大化。
大体思路:
按时间由大到小,时间相同则按等级由高到低,将任务和机器分别排序。然后从第一个任务开始,挑选最合适的机器将其完成。最合适的原则是:时间大于该任务且等级最低。检索完所有的任务即可得到结果。
看到网上聚聚的思路,将时长符合要求的机器分成不同的等级保存在一个数组里。这样实际上简化了机器的数据,效率更高。
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; struct node { int x,y; } s1[100005],s2[100005]; int cmp(node a,node b) { if(a.x == b.x) return a.y>b.y; return a.x>b.x; } int main() { int n,m,i,j,cnt; __int64 sum; while(~scanf("%d%d",&n,&m)) { for(i = 0; i<n; i++) scanf("%d%d",&s1[i].x,&s1[i].y); for(i = 0; i<m; i++) scanf("%d%d",&s2[i].x,&s2[i].y); sort(s1,s1+n,cmp); sort(s2,s2+m,cmp); cnt = sum = 0; int c[105] = {0}; for(i = 0,j = 0; i<m; i++) { while(j<n && s1[j].x>=s2[i].x) { c[s1[j].y]++; j++; } for(int k = s2[i].y; k<=100; k++) { if(c[k]) { c[k]--; sum+=(s2[i].x*500+s2[i].y*2); cnt++; break; } } } printf("%d %I64d\n",cnt,sum); } }
Task
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6721 Accepted Submission(s): 1786
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 2100 3100 2100 1
Sample Output
1 50004
0 0
- HDU4864_Task_贪心
- 贪心!
- 贪心~
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- Java Script 小笔记
- hihocoder1044
- cmd命令行中javac报错:类HelloWorld是公有的,应在名为HelloWorld.java的文件中声明,public class HelloWorld
- 【Error】: rpm: arguments to --root (-r) must begin with a /
- Bootstarp实现一列固定 另外一列随元素增高 但不影响其他列的方式
- HDU4864_Task_贪心
- Bzoj 2683: 简单题(CDQ分治)
- Android不同APP之间三种共享数据的方式
- 如果遇到删除文件删不了,连粉碎也粉碎不了,使用以下方法
- 结构体对齐详解
- 关于线程中的wait、notify以及sleep的一些学习体会
- 远程调用原理与对比(RMI、MINA、ESB、Hessian、SOAP、EJB)
- python—利用matplotlib库画图
- 两天了解scala