hdu 4864 排序+枚举
来源:互联网 发布:网络彩票赌博的量刑 编辑:程序博客网 时间:2024/05/21 10:03
Task
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4580 Accepted Submission(s): 1202
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
分析:定义一个结构体,用来存放机器或任务的时间的等级,然后分别建立两个结构体数组,分别存放机器和任务。排序优先按照时间排序,在按照等级排序,工作时间长,等级高的机器当然是来完成时间长等级高的任务,接下来依次枚举每个任务,把可以完成当前任务时间的机器保存起来,然后从当前任务的等级开始枚举,看一下保存在数组中的是否存在一个机器的等级>=任务等级,如果存在,那么就计算这个任务。保存机器的数组要减去这台机器,因为已经用过了。然后再去枚举下一个任务
#include<iostream>#include<string>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>#define LL long longusing namespace std;const int maxn=100005;int N,M;struct node{ int x; int y;};bool cmp(node a,node b){ if(a.x==b.x)return a.y>b.y; return a.x>b.x;}int main(){ while(scanf("%d%d",&N,&M)!=EOF){ node mac[maxn],tak[maxn]; for(int i=0;i<N;i++) scanf("%d%d",&mac[i].x,&mac[i].y); for(int i=0;i<M;i++) scanf("%d%d",&tak[i].x,&tak[i].y); sort(mac,mac+N,cmp); sort(tak,tak+M,cmp); int a[105]; LL sum=0,cnt=0; memset(a,0,sizeof(a)); for(int i=0,j=0;i<M;i++){ while(j<N&&mac[j].x>=tak[i].x){ a[mac[j].y]++; j++; } for(int k=tak[i].y;k<101;k++){ if(a[k]){ a[k]--; cnt++; sum+=500*tak[i].x+2*tak[i].y; break; } } } cout<<cnt<<' '<<sum<<endl; }}
0 0
- hdu 4864 排序+枚举
- hdu-1425(排序||枚举)
- HDU 6127 Hard challenge(极角排序+枚举点)
- 枚举排序
- HDU 4500 小Q系列故事——屌丝的逆袭(模拟枚举排序)
- HDU 1007 Quoit Design 仅仅只是枚举了x排序后的三个数......
- 【枚举排序】生成可重集排序
- MPI 枚举排序实现
- OpenMP之枚举排序
- 枚举类型排序
- hdu 3332 暴力枚举
- hdu 4007 枚举 Dave
- hdu 4068 枚举 SanguoSHA
- hdu 1015 Safecracker(枚举)
- hdu 1087 枚举+DP
- hdu 1158 枚举+DP
- HDU 4353 枚举
- HDU 3823 暴力枚举
- C++ Primer Plus(第六版)--学习杂记(第三章)
- QtScript
- python 插入排序
- java mail 发邮件完整实现
- Spring MVC Exception Handling Example
- hdu 4864 排序+枚举
- 剑指 offer:用两个栈实现队列
- Linux中find常见用法示例
- 在linux下使用w3m浏览网页
- CPU报高,SQLServer如何排查
- MyBatis学习总结(六)——调用存储过程
- Android-Tips
- EXCEL 下拉时不使用自动增加
- linux访问windows共享文件夹