设为首页 加入收藏

TOP

hdu4864Task(贪心)
2015-07-20 18:04:14 来源: 作者: 【 】 浏览:2
Tags: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.
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 The following M lines each contains two integers xi(0 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
    
     
#include
     
       #include
      
        #include
       
         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; } 
       
      
     
    


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU2504 又见GCD 下一篇HDU 1325 Is It A Tree? 并查集

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: