hdu 4864
来源:互联网 发布:淘宝服装店货源七浦路 编辑:程序博客网 时间:2024/06/06 13:24
Task
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1930 Accepted Submission(s): 496
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
Author
FZU
Source
2014 Multi-University Training Contest 1
基本思想是贪心。
对于价值c=500*xi+2*yi,yi最大影响100*2<500,所以就是求xi总和最大。可以先对机器和任务的时间从大到小排序。从最大时间的任务开始,找出满足任务时间要求的所有机器,从中找出等级最低且满足任务等级要求的机器匹配。依次对任务寻找满足要求的机器。
用multiset可以处理相同值的情况,erase()的参数可以是迭代器,也可以是元素值
#include<stdio.h>#include<algorithm>#include<set>#define N 100005using namespace std;multiset<int>g;struct node{ int x,y;}a[N],b[N];bool cmp(node a,node b){ if(a.x!=b.x) return a.x>b.x; else return a.y>b.y;}int main(){ //freopen("1004.in","r",stdin); //freopen("1004.out","w",stdout); int n,m,i,j,num; long long sum; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<n;i++) scanf("%d%d",&a[i].x,&a[i].y); for(i=0;i<m;i++) scanf("%d%d",&b[i].x,&b[i].y); sort(b,b+m,cmp); sort(a,a+n,cmp); j=0;num=0,sum=0; g.clear(); for(i=0;i<m;i++) { while(j<n&&a[j].x>=b[i].x) { g.insert(a[j].y); j++; } multiset<int>::iterator it=g.lower_bound(b[i].y); if(it!=g.end()) { num++; sum+=500*b[i].x+2*b[i].y; g.erase(it); } } printf("%d %I64d\n",num,sum); } return 0;}
#include<stdio.h>#include<algorithm>#include<set>#define N 100005using namespace std;multiset<int>g[105];struct node{ int x,y;}b[N];bool cmp(node a,node b){ if(a.x!=b.x) return a.x>b.x; else return a.y>b.y;}int main(){ //freopen("1004.in","r",stdin); //freopen("1004.out","w",stdout); int n,m,i,j,num,x,y; long long sum; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<=100;i++) g[i].clear(); for(i=0;i<n;i++) { scanf("%d%d",&x,&y); g[y].insert(x); } for(i=0;i<m;i++) scanf("%d%d",&b[i].x,&b[i].y); sort(b,b+m,cmp); num=0,sum=0; for(i=0;i<m;i++) { x=b[i].x; y=b[i].y; for(j=y;j<=100;j++) { if(g[j].empty()==true) continue; multiset<int>::iterator it=g[j].lower_bound(x); if(it!=g[j].end()) { num++; sum+=500*b[i].x+2*b[i].y; g[j].erase(it);//删除当前迭代器指向的元素 break; } } } printf("%d %I64d\n",num,sum); } return 0;}
0 0
- hdu 4864
- hdu 4864
- hdu 4864
- hdu 4864
- hdu 4864
- hdu 4864
- HDU 4864
- HDU 4864
- hdu 4864 Task 贪心
- hdu 4864 Task 贪心
- HDU 4864(Task)
- HDU 4864 Task
- HDU 4864 Task(贪心)
- HDU 4864 Task(贪心)
- hdu-4864-Task
- 【HDU 4864】Task【贪心】
- Hdu-4864-Task
- HDU 4864 Task
- C++ pair的用法
- cocos2dx lua 热更新
- AndroidSettings源代码分析
- Laravel配置路由
- 这竟然是全世界最好的模式(商业大佬为之咂舌)
- hdu 4864
- 如何在程序中添加svn版本信息
- 简单工厂方法
- The connection to adb is down的解决方法
- div半透明遮罩效果
- 2015最好用的浏览器
- shell字符串的截取
- Android的Message机制
- Android extsd open failed: EACCES (Permission denied)