Task(二维关键字不同且有向的贪心思想(有坑点,反向求会wa。。))
来源:互联网 发布:网络扫描技术揭秘 下载 编辑:程序博客网 时间:2024/05/23 19:11
Link:http://acm.hdu.edu.cn/showproblem.php?pid=4864
Task
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4606 Accepted Submission(s): 1207
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
编程思想:贪心。题目很特别的给出了获得金钱的计算公式为500*x+2*y,y<=100,也就是说y怎么样也没有x变化1价值增加的多,所以我们要优先保护x,所以在二级排序的时候先以x,再y,这样就可以在保证个数最大的情况下价值最大了,整个过程还是简单贪心,所以可以按任务时间从大到小排序,然后每个任务找出大于等于该任务难度且与难度最接近(sett.lower_bound(task[i].yi)函数)的机器完成该任务。
AC code:
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>#include<queue>#include<map>#include<stack>#include<vector>#include<set>#define LL long long#define MAXN 1000010using namespace std;struct node{int xi;//时间 int yi;//級別 bool operator < (const node &b)const{if(xi!=b.xi)return xi>b.xi;elsereturn yi>b.yi;}}machine[MAXN],task[MAXN];multiset<int>sett;multiset<int>::iterator it;LL ans;int cnt;int main(){//freopen("D:\\in.txt","r",stdin);int T,i,j,n,m; while(~scanf("%d%d",&n,&m)) {sett.clear();for(i=1;i<=n;i++){scanf("%d%d",&machine[i].xi,&machine[i].yi);}for(i=1;i<=m;i++){scanf("%d%d",&task[i].xi,&task[i].yi);}sort(machine+1,machine+n+1);sort(task+1,task+m+1);j=1;ans=0;cnt=0;for(i=1;i<=m;i++){while(j<=n&&machine[j].xi>=task[i].xi){sett.insert(machine[j].yi);j++;}if(sett.empty()){continue;}it=sett.lower_bound(task[i].yi);if(it!=sett.end()){ans+=500*(task[i].xi)+2*(task[i].yi);cnt++;sett.erase(it);}}printf("%d %I64d\n",cnt,ans);} return 0;}
0 0
- Task(二维关键字不同且有向的贪心思想(有坑点,反向求会wa。。))
- 图的贪心(类似拓扑:都是有向图)
- 确定比赛名次(拓扑排序模板(比之前的模板纠正和完善了,之前的会有bug,一些题有时会wa))
- hdoj4864 Task (贪心)
- hdu4864 Task(贪心)
- 求有向面积(多边形面积)
- 关于网络状态改变监听广播的使用(android不同系统版本会有不同)
- hdu4268 Alice and Bob(二维贪心的固定思想 STL的multiset的二分查找函数实现)
- (贪心)kruskal思想
- hdu 4864 Task(贪心)
- hdu 4864 Task(贪心)
- hdu 4864 Task (贪心)
- HDU-4864 Task(贪心)
- HDOJ 4864 Task(贪心)
- HDU 4864 Task(贪心)
- hdu 4864 Task (贪心)
- POJ 1018(多关键字排序还在wa…)
- HDU 1535 Invitation Cards 有向图的来回最短路(邻接表反向建图)+spfa
- 静态测试及评审、测试用例
- IOS 小例子,输出一个图形的坐标,颜色,形状-2。
- 字符串的初始化及数组、指针
- Java中转换流的相关用法
- 项目优化总结
- Task(二维关键字不同且有向的贪心思想(有坑点,反向求会wa。。))
- Android 开源框架Universal-Image-Loader完全解析(三)---源代码解读
- 缺陷报告的主要内容
- 深入研究 Java Synchronize 和 Lock 的区别与用法
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问
- 常用的颜色搭配选择参考
- FTI们在使用的开源库
- 记录——《C Primer Plus (第五版)》第八章编程练习第五题
- gcd & lcm