hdu 4864 Task

本文介绍了一个关于任务分配的问题,公司需要使用有限的机器资源完成尽可能多的任务并获取最大利润。通过对任务和机器按特定条件排序,采取最优策略完成任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Task

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2108    Accepted Submission(s): 536


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<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 2 100 3 100 2 100 1
 

Sample Output
  
1 50004
 

Author
FZU
 

Source
 

题目:一家公司有m个任务需要完成,每件任务有一个最少工作时间和一个任务难度,同时这家公司一共有n台机器,每台对应一个最大工作时间和机器的等级,用这n台机器来完成任务。每台机器每天能完成一件任务----这件任务的需要的工作时间和任务难度分别要不超过机器的最长工作时间和机器的等级,每完成一件任务,公司获得500*任务工作时间+2*任务等级的利润。给定这些任务和机器的详细情况,问最多能完成多少件任务,利润是多少?(多种情况时输出最大利润)


题解:比赛的时候,看了看过的队伍很多,但是正确率却很低,自己也没出这道题。比赛后看了题解才做出来的。

            题解的意思就是----每完成一件任务,获得利润=500*t+2*w,这里w的范围是1-100,最大值W=200<500对于整体利润的影响很小,所以对任务和时间均按照t递减排序,t相同按照w递减排序。然后从第一件任务开始遍历,找出所有能够解决这项任务的机器,并挑出工作时间最少,并且等级最低的那台来完成这项任务,以此类推,直到所有任务都完成。

         为什么要这样安排呢?任务排序之后,后边的任务的一部分是时间与当前任务时间相同,但任务等级低的,能过解决当前任务的机器比人能够完成剩下的任务;另外一部分是时间比当前任务短,任务等级比当前任务高的,假设我挑走一台等级高机器,这台机器能完成这两项任务,另外存在一台机器等级低的机器只能完成当前任务,如果我用等级高的那台来完成当前任务的话,后来的任务就不能完成了,所以我要选择等级低但是能完成当前任务的那台机器;第三种情况,时间短,任务等级低的,能够完成当前任务的那些机器必然能用来完成这些任务。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef __int64 LL;

struct node{
  int x,y;
}l[100010],r[100010];

bool cmp(node a,node b)
{
    if(a.x!=b.x)
        return a.x>b.x;
    return a.y>b.y;
}
int main()
{
    int m,n;
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        for(int i=0;i<m;i++)
            scanf("%d%d",&l[i].x,&l[i].y);
        for(int j=0;j<n;j++)
            scanf("%d%d",&r[j].x,&r[j].y);

        sort(l,l+m,cmp);
        sort(r,r+n,cmp);

        LL ans=0,num=0;
        int c[110],i,j;
        memset(c,0,sizeof(c));

        for(i=0,j=0;i<n;i++)
        {
            while(j<m&&l[j].x>=r[i].x)
            {
                c[l[j].y]++;
                j++;
            }
            for(int k=r[i].y;k<=100;k++)
            {
                if(c[k])
                {
                    c[k]--;
                    num++;
                    ans+=500*r[i].x+2*r[i].y;
                    break;
                }
            }
        }
        printf("%I64d %I64d\n",num,ans);
    }
    return 0;
}




### 杭州电子科技大学操作系统实验一概述 Linux内核编译及添加系统调用是杭州电子科技大学操作系统课程中的一个重要实验内容[^3]。此实验旨在让学生深入了解Linux系统的内部工作原理以及如何扩展其功能。 #### 实验目标 通过本实验,学生能够掌握以下技能: - 编译完整的Linux内核源码树并安装新构建的内核镜像文件。 - 修改现有的系统调用来创建自定义版本或者新增加新的系统调用接口。 - 使用`gcc`工具链来交叉编译适用于不同架构的目标平台上的可执行程序。 - 测试所编写的新特性是否按预期正常运行。 #### 主要操作步骤 为了完成上述任务,具体的操作流程如下所示: 1. **准备环境** 安装必要的依赖包以支持后续的工作,比如`build-essential`, `libncurses-dev`等开发库。 2. **获取官方发布的稳定版内核源代码** 可以从kernel.org下载最新的稳定发行版本作为基础进行定制化改造。 3. **配置选项设置** 利用菜单驱动式的界面(`make menuconfig`)调整各项参数直至满足需求为止。 4. **实际改动部分——向系统引入额外的时间统计函数** - 在`arch/x86/entry/syscalls/syscall_64.tbl`中注册一个新的条目用于表示即将加入的服务项; - 更新头文件`include/linux/syscalls.h`声明原型以便其他组件引用; - 开发具体的业务逻辑位于`kernel/sys.c`之内实现期望的行为; - 构建整个项目结构并通过一系列单元检验确认无误之后部署至真实环境中试用。 5. **验证成果的有效性** 设计专门的应用场景模拟真实的请求过程从而评估性能指标是否达到标准范围以内。 ```c // syscall_64.tbl 中增加一行 335 64 sys_my_syscall __x64_sys_my_syscall // syscalls.h 添加声明 asmlinkage long sys_my_syscall(int pid); // sys.c 实现方法体 SYSCALL_DEFINE1(my_syscall, int, pid){ struct task_struct *task; unsigned long user_time, kernel_time; rcu_read_lock(); task = find_get_pid(pid); if (!task) { rcu_read_unlock(); return -ESRCH; /* No such process */ } getrusage(task, RUSAGE_BOTH, &ru); user_time = ru.ru_utime.tv_sec*HZ + ru.ru_utime.tv_usec/(1000000/HZ); kernel_time = ru.ru_stime.tv_sec*HZ + ru.ru_stime.tv_usec/(1000000/HZ); rcu_read_unlock(); // 将结果复制给用户空间缓冲区 copy_to_user(buf, (void*)&user_time, sizeof(unsigned long)); copy_to_user((char*)buf+sizeof(unsigned long), (void*)&kernel_time, sizeof(unsigned long)); return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值