UVa 11389 - The Bus Driver Problem
来源:互联网 发布:网络监控布线 编辑:程序博客网 时间:2024/05/24 03:20
题目:有n个上午的任务和下午的任务,分配给司机,如果工作总时间超过d,超过的部分要给加班费;
现在让你安排任务,问最小的加班分花费。
分析:贪心。将两个任务分别按递增和递减序排序,每个对应边号的一组即可。
设序列中的两组配对的元素为m1,a1,m2,a2 且 m1≤m2,a1≤a2;
则配对方式<m1,a2>,<m2,a1>优于<m1,a1>,<m2,a2>(浪费的可能更少)。
说明:(⊙_⊙)。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>using namespace std;int morni[101];int after[101];int cmp1(int a, int b){ return a < b; }int cmp2(int a, int b){ return a > b; }int main(){int n,d,r;while (~scanf("%d%d%d",&n,&d,&r) && n) {for (int i = 0 ; i < n ; ++ i)scanf("%d",&morni[i]);for (int i = 0 ; i < n ; ++ i)scanf("%d",&after[i]);sort(morni, morni+n, cmp1);sort(after, after+n, cmp2);int sum = 0;for (int i = 0 ; i < n ; ++ i) if (morni[i]+after[i] > d)sum += r*(morni[i]+after[i]-d);printf("%d\n",sum);} return 0;}
0 0
- Uva Oj 11389 - The Bus Driver Problem
- Uva-11389-The Bus Driver Problem
- uva 11389 The Bus Driver Problem
- UVA - 11389 The Bus Driver Problem
- UVA 11389 - The Bus Driver Problem (贪心)
- UVA 11389 - The Bus Driver Problem
- UVa 11389 - The Bus Driver Problem
- UVA - 11389 The Bus Driver Problem 贪心
- UVA - 11389 The Bus Driver Problem
- 【UVa】11389 - The Bus Driver Problem
- UVa 11389 The Bus Driver Problem
- UVA - 11389 The Bus Driver Problem
- UVA 11389 The Bus Driver Problem(贪心)
- UVA 11389 The Bus Driver Problem .
- UVa 11389 The Bus Driver Problem
- UVA 11389 The Bus Driver Problem(贪心)
- UVA 11389——The Bus Driver Problem
- uva 11389 - The Bus Driver Problem(贪心)
- servlet过滤器
- Binary Tree Preorder Traversal
- 为什么要使用Python?
- ipcs 和 ipcrm 命令
- 视频聊天软件的技术实现
- UVa 11389 - The Bus Driver Problem
- CShell
- 关于通过vmware安装windows8的几个问题及解决--无人参与应答文件包含的产品密钥无效
- 用profiler工具对android ndk程序进行性能分析
- JSP中文乱码问题终极解决方案
- Qt调用DLL动态库接口函数程序崩掉
- Deepflow 初步架构
- Big Endian 和 Little Endian
- linux以tree树状图逐级列出目录的内容