14多校第一场 1004(HDU4864)Task

1004(HDU4864) Task

题目描述:

Today the company has m tasks to complete. The ith task need ximinutes to complete. Meanwhile, this task has a difficulty level yi. Themachine whose level below this task’s level yi cannot complete this task. Ifthe company completes this task, they will get (500*xi+2*yi) dollars.
The company has n machines. Each machine has amaximum working time and a level. If the time for the task is more than themaximum 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 completedby one machine.
The company hopes to maximize the number of thetasks which they can complete today. If there are multiple solutions, theyhopes to make the money maximum.

 

大意:

 

工厂有m任务和n个机器,每个任务有它所需的时间和等级,机器同样如此,每个机器只能做一件任务,完成每件任务的得到 500*时间+200*等级  这么多钱,问最多能收获多少钱?

 

官方题解:

 

基本思想是贪心。

对于价值c=500*xi+2*yi,yi最大影响100*2<500,所以就是求xi总和最大。可以先对机器和任务的时间从大到小排序。从最大时间的任务开始,找出满足任务时间要求的所有机器,从中找出等级最低且满足任务等级要求的机器匹配。依次对任务寻找满足要求的机器。

 

代码:

复杂度是 nlogn的,利用STL

/**

吉林大学
Jilin U

Statement:  以下代码完全由作者个人完成,不存在抄袭、套用。
Author:     sinianluoye (JLU_LiChuang)
Date:       2014-07-22
Usage:      多校第一场

**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>

#define ll long long
#define eps 1e-8
#define ms(x,y) (memset(x,y,sizeof(x)))
#define fr(i,x,y) for(int i=x;i<=y;i++)

using namespace std;

struct task
{
    int t,w;
};

bool cmp(task a,task b)
{
    if(a.t!=b.t)return a.t>b.t;
    else return a.w>b.w;
}

const int maxn=1e5+10;

task tas[maxn],mac[maxn];

int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        ms(used,0);
        for(int i=1;i<=n;i++)
            scanf("%d%d",&mac[i].t,&mac[i].w);
        for(int i=1;i<=m;i++)
            scanf("%d%d",&tas[i].t,&tas[i].w);
        sort(mac+1,mac+n+1,cmp);
        sort(tas+1,tas+m+1,cmp);

        ll num=0,ans=0;
        multiset<int>s;
        for(int i=1,j=1;i<=m;i++)
         {
             while(j<=n&&mac[j].t>=tas[i].t)
                 s.insert(mac[j++].w);
             multiset<int>::iterator p=s.lower_bound(tas[i].w);
             if(p!=s.end())
             {
                num++;
                ans+=500*tas[i].t+2*tas[i].w;
                s.erase(p);
             }
         }
         cout<<num<<' '<<ans<<endl;
    }
    return 0;
}

/*************copyright by sinianluoye (JLU_LiChuang)***********/



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的体育馆管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本体育馆管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此体育馆管理系统利用当下成熟完善的SpringBoot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线选择试题并完成答题,在线查看考核分数。管理员管理收货地址管理、购物车管理、场地管理、场地订单管理、字典管理、赛事管理、赛事收藏管理、赛事评价管理、赛事订单管理、商品管理、商品收藏管理、商品评价管理、商品订单管理、用户管理、管理员管理等功能。体育馆管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:体育馆管理系统;SpringBoot框架;Mysql;自动化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值