uva_1422 Processor
题目链接
题意:
有n个任务, 每个任务要在规定的时间[l, r]内完成, 工作量为 w, 每个任务可以分开完成。
求, 使得所有任务都完成的最大速度的最小值。
思路:
最大值最小问题, 二分。
因为是要完成所有任务, 所以先按开始时间排序, 接下来二分速度。
因为任意两个任务之间的关系只有两种, 1)相交或者包含 2)相切或者相离
如果是情况 2) 那么不需要特殊处理, 按顺序处理过去即可。
如果是情况 1) 那么需要将这个时间段内的任务按照结束时间来进行处理, 结束时间小的优先完成。
然后枚举时间, 从1 开始处理过去, 看是否能处理完所有任务即可。
代码:
1 #include <cmath> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <ctime> 6 #include <set> 7 #include <map> 8 #include <list> 9 #include <stack> 10 #include <queue> 11 #include <string> 12 #include <vector> 13 #include <fstream> 14 #include <iterator> 15 #include <iostream> 16 #include <algorithm> 17 using namespace std; 18 #define LL long long 19 #define INF 0x3f3f3f3f 20 #define MOD 1000000007 21 #define eps 1e-6 22 #define MAXN 10010 23 #define MAXM 100 24 #define dd {cout<<"debug"<<endl;} 25 #define pa {system("pause");} 26 #define p(x) {printf("%d\n", x);} 27 #define pd(x) {printf("%.7lf\n", x);} 28 #define k(x) {printf("Case %d: ", ++x);} 29 #define s(x) {scanf("%d", &x);} 30 #define sd(x) {scanf("%lf", &x);} 31 #define mes(x, d) {memset(x, d, sizeof(x));} 32 #define do(i, x) for(i = 0; i < x; i ++) 33 #define dod(i, x, l) for(i = x; i >= l; i --) 34 #define doe(i, x) for(i = 1; i <= x; i ++) 35 struct node 36 { 37 int l; 38 int r; 39 int t; 40 int no; 41 bool operator < (const struct node &y) const 42 { 43 return r > y.r; 44 } 45 }; 46 int n, sum; 47 struct node f[MAXN]; 48 int w[MAXN]; 49 bool cmp(const struct node &x, const struct node &y) 50 { 51 return x.l == y.l? x.r < y.r : x.l < y.l; 52 } 53 void read() 54 { 55 sum = 0; 56 scanf("%d", &n); 57 for(int i = 0; i < n; i ++) 58 { 59 scanf("%d %d %d", &f[i].l, &f[i].r, &f[i].t); 60 sum += f[i].t; 61 f[i].no = i; 62 } 63 sort(f, f + n, cmp); 64 } 65 bool is_ok(int x) 66 { 67 priority_queue <struct node> Q; 68 for(int i = 0; i < n; i ++) 69 w[f[i].no] = f[i].t; 70 int i = 0; 71 int pos = 1; 72 while(true) 73 { 74 while(i < n && f[i].l <= pos) Q.push(f[i ++]); 75 76 int ts = x; 77 while(!Q.empty() && ts) 78 { 79 struct node temp = Q.top(); 80 81 if(temp.r <= pos) return false; 82 83 w[temp.no] -= ts; 84 if(w[temp.no] > 0) 85 ts = 0; 86 else if(w[temp.no] <= 0) 87 { 88 ts = -w[temp.no]; 89 Q.pop(); 90 } 91 } 92 93 if(i == n && Q.empty()) return true; 94 pos ++; 95 } 96 return false; 97 } 98 int get_ans() 99 { 100 int l = 1, r = sum; 101 while(l <= r) 102 { 103 int mid = (l + r) / 2; 104 if(is_ok(mid)) 105 r = mid - 1; 106 else 107 l = mid + 1; 108 } 109 return l; 110 } 111 112 int main() 113 { 114 int T; 115 scanf("%d", &T); 116 while(T --) 117 { 118 read(); 119 printf("%d\n", get_ans()); 120 } 121 return 0; 122 }
View Code
转载于:https://www.cnblogs.com/By-ruoyu/p/4871431.html
uva_1422 Processor相关推荐
- Pliops XDP(Extreme Data Processor)数据库存储设计的新型加速硬件
文章目录 0 前言 1 核心问题 1.1 引擎的各方面性能受限于数据结构的选择 1.2 压缩功能 导致的CPU瓶颈 1.3 Crash-safe 崩溃异常的无奈选择 1.4 当前主流 加速硬件 较难满 ...
- 【Cmake】执行cmake命令时报错:No XSLT processor found
一.问题描述 在ubuntu中,在生成Doc(文档)中,执行cmake命令时报错:No XSLT processor found 二.原因查找 google该错误信息,原因是确实ubuntu中没有安装 ...
- html5 audio标志改变音量,HTML5之Audio(二)—— processor调节音量
Audio var AudioContext = AudioContext || webkitAudioContext || mozAudioContext || msAudioContext, // ...
- PXA270-基于ARM9内核Processor外部NAND FLASH的控制实现
于ARM9内核Processor外部NAND FLASH的控制实现 夏 涛 (上海交通大学微电子学院 上海 200030) 1 NAND FLASH NAND写回速度快.芯片面积小,特别是大容量使其优 ...
- Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题
B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...
- Elasticsearch 摄取节点(Ingest Node)常用的数据处理器(Processor)
文章目录 Set Processor Append Processor Remove Processor Rename Processor Convert Processor Grok Process ...
- springbatch的writer、processor、reader复杂太难用?使用tasklet更方便!
writer.processor.reader复杂太难用,使用mybatis太复杂,操作数据库太复杂,一不小心还会配置出错. 使用tasklet更加方便! @Component public clas ...
- Xilinx IP解析之Processor System Reset v5.0
一. IP概述 可参考Xilinx官网Processor System Reset Module概述, 以下翻译自官网此IP的概述. 产品描述: Xilinx处理器系统复位模块允许客户通过设置某些参数 ...
- Spring Boot——[Spring Boot Configuration Annotation Processor not found in classpath]解决方案
问题描述 使用Spring Boot开发的过程中,写读取Properties配置文件的配置类时提示Spring Boot configuration annotation processor not ...
最新文章
- python数据存储与读取_【Python爬虫】数据保存与读取
- 文件系统与数据库的优缺点
- 画原理图和PCB图该注意什么?
- Navcat:1251 client does not support ...问题
- php text(),PHP+TEXT留言本(一)
- python-day19-面向对象进阶-加载顺序,命名空间,组合(实现松耦合)
- DBCP,C3P0,Proxool,BoneCP参数介绍[摘]
- 每天一个PS技巧(原理+实践)——简单背景的抠图与毛发抠图
- dev、test、pre和prod是什么意思?
- c程序设计第五版谭浩强课后答案 第四章习题答案
- 行测题中逻辑判断题的规律
- 操作系统:作业调度算法--先来先服务
- burntest Linux参数,限拷机软件IntelBurnTest 2.0
- Centos7脚本一键优化
- Axure RP Pro 相关问题 导出成PDF
- Java Long类型对比
- 慕课作业互评(使用脚本自动互评)
- IF函数多个条件判断及嵌套
- 统计学基础——负二项分布的数字特征
- 工作站和台式机的区别是什么
热门文章
- C++ string类常用函数
- [vSphere培训实录]8G内存笔记本搭建vSphere测试环境
- 问题 D: Search Problem
- oracle数据库 bug,Oracle bug之vipca无法执行问题的解决
- 今日恐慌与贪婪指数为75 贪婪程度有所上升
- 24小时BTC合约大单成交1.52亿美元 现货大单成交1亿美元
- SAP License:什么是ERP供应链
- SAP License:中国集团管控存在的主要问题-已加入点评
- 智慧电商erp通用版管理系统+采购管理+仓库管理+订单管理+财务管理+系统管理+Axure高保真交互ERP通用版电商web端管理系统+全局说明+竞品分析+协同办公
- 小微企业——信用风险与放款原则分析