题目为:
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 (500xi+2yi) 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 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.
输出

输入格式:

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.

输入样例:

在这里给出一组输入。例如:
1 2
100 3
100 2
100 1

输出样例:

在这里给出相应的输出。例如:
1 50004

简单总结解决这个问题思路:
先把机器和任务结构体数组排个序,先优先按xi从大到小,在考虑yi.因为xi要乘以500,比重大。刚开始进入误区,把排好序的任务第一个优先考虑,直接在排好序的机器中找,只要符合条件(机器的时间和等级都要小于任务的),这是一个考虑不周全的。因为还要让任务完成的数量还要最多,这也是一个得到最优解的要求。所以需要在思考一下。把任务比重大的给它安排时,不能随便的安排一个机器,需要先在时间条件满足情况下,选择等级符合条件,且等级最小的这些机器,则会等级大的机器出来,可以安排更多的任务。从而使完成任务数量最多。在这个过程中有2个最优子的过程
代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef struct good
{int x,y;
}good;
good mach[100005],task[100005];
bool comp(good a,good b)
{if(a.x==b.x)return a.y>b.y;return a.x>b.x;
}
int main()
{int n,m,num,x,y,level[105];long sum;while(scanf("%d%d",&n,&m)!=EOF){memset(level,0,sizeof(level));//level用来符合条件的机器位置for(int i=0;i<n;i++)scanf("%d%d",&mach[i].x,&mach[i].y);for(int i=0;i<m;i++)scanf("%d%d",&task[i].x,&task[i].y);sort(mach,mach+n,comp);sort(task,task+m,comp);num=0; sum=0; //完成任务个数,收益 int j=0;for(int i=0;i<m;i++){while(j<n&&mach[j].x>=task[i].x) level[mach[j++].y]++;//在机器中找先找时间大于任务时间的,把这些机器位置记录下来 for(int lev=task[i].y; lev<=100;lev++)//在上面记录机器中,再找>=任务等级 ,选机器任务等级符合要求最小的那个 if(level[lev]){num++; sum+=500*task[i].x+2*task[i].y; level[lev]--;break;}}cout<<num<<' '<<sum<<endl;}
}

运行结果:

1 2
100 3
100 2
100 1
1 50004
//可以继续输入

c++工厂机器安排(贪心)相关推荐

  1. 工厂机器安排(贪心算法)

    题目来源:HDOJ 一.题目介绍 Today the company has m tasks to complete. The ith task need xi minutes to complete ...

  2. [CQOI2012]模拟工厂 题解(搜索+贪心)

    [CQOI2012]模拟工厂 题解(搜索+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1327574 链接题目地址:洛谷P3161 BZOJ P26 ...

  3. 活动安排--贪心算法C语言实现

    一.前言 大三下的算法设计分析课程.每周必备二道算法题.头疼.自己写的,大家看看就行.题目,我就截图 ,懒得赋文字了. 二.内容 代码: #include<stdio.h> typedef ...

  4. 活动安排(贪心算法)C/C++

    样例输入 4 10 1 3 2 4 5 7 9 10 样例输出 3 下面看一下一个贪心算法的典型例题 活动选择问题 有n个需要在同一天使用同一个教室的活动a1,a2,-,an,教室同一时刻只能由一个活 ...

  5. P2514-[HAOI2010]工厂选址【贪心】

    正题 题目链接:https://www.luogu.org/problemnew/show/P2514 题目大意 有一个厂,需要bbb吨煤炭,然后第jjj个矿运到该厂的运费为c0,jc_{0,j}c0 ...

  6. 预测性维护_工厂数据的预测性维护

    预测性维护 In the era of digitization the concept of Smart Factory attracts a lot of attention. Modern in ...

  7. 算法设计与分析 实验二 贪心算法

    实验2.<贪心算法实验> 一.实验目的 了解贪心算法思想 掌握贪心法典型问题,如背包问题.作业调度问题等. 二.实验内容 编写一个简单的程序,实现单源最短路径问题. 编写一段程序,实现找零 ...

  8. 工业以太网交换机在工厂环境中使用需要注意哪些问题?

    工业交换机也称作工业以太网交换机,即应用于工业控制领域的以太网交换机设备,由于采用的网络标准,其开放性好.应用广泛以及价格低廉.使用的是透明而统一的TCP/IP协议,以太网已经成为工业控制领域的主要通 ...

  9. 3d数字孪生-智慧工厂可视化三维建模展示系统

    伴随我国工业转型数字化的不断推进,企业厂区以智能制造为核心的智慧厂房计划正不断加速落地实施,越来越多的制造企业逐步加入工业数字化智慧厂房智能制造生产的行列中,商迪3D力求在智慧厂房建设中加强5G技术在 ...

最新文章

  1. NumPy迎来重大版本更新,新增函数注释、滑动窗口视图功能,仅支持Python 3.7以上版本...
  2. linux给oracle导入sql语句,Linux数据库创建与数据导入
  3. php设计模式的六大原则(六):迪米特法则
  4. SpringBoot+Shiro学习(四):Realm授权
  5. 帧同步和状态同步(二)案例分析
  6. 马赛克 php,php实现图片局部打马赛克的方法
  7. OpenCV4.0 快速QR二维码检测测试示例
  8. 怎么找到python的文件_python – 如何找到文件所在的挂载点?
  9. 如何做到行业顶尖位置?
  10. 结构体(struct)与类(class)
  11. Mybatis-Plus注解自定义sql分页查询
  12. 【JAVA】poi操作,excel读取数据。
  13. 用HTML+CSS做员工信息登记表
  14. linux文件权限651,Linux基础之文件权限详解
  15. 随笔 - 记录下当前的生活
  16. 淘宝省钱_如何省钱和组装自己的电路板
  17. 安装win2003 R2 SP2 x64 可用密钥
  18. linux之OPERATION(运维)一
  19. Python3 网络爬虫. 4
  20. 6.3.1广度优先搜索

热门文章

  1. 查询计算机u盘记录时间,怎么通过系统日志查看u盘的拔出时间
  2. ORA-15018: diskgroup cannot be created
  3. ARCGIS导入数据后,属性表为空
  4. 学计算机课业压力,关于学习负担、学业负担及课业负担的一段解释
  5. DM MPP部署问题
  6. 手把手教你如何用PS抠白底图教程
  7. 屏幕录像机(bb flashback pro 4)pjb v4.1.21
  8. 【转载】一些软件设计原则
  9. 算法训练营学习笔记2
  10. python处理字体(动态字体库)