题目链接:UVA - 11389

题意描述:有n个司机,n个早班路线和n个晚班路线,给每个司机安排一个早班路线和一个晚班路线,使得每个早班路线和晚班路线只属于一个司机。如果一个司机早班和晚班总的驾驶时间超过d,那么超出的时间按每小时r元付给司机。求最小的费用。

算法分析:一枚贪心的小水题。对早班路线的时间按照从大到小排序,对晚班路线的时间按照从小到大排序,然后就可以了。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+; int n,d,r,an[maxn],bn[maxn]; int cmp(int i,int j) {return i>j; } int main()
{
while (scanf("%d%d%d",&n,&d,&r)!=EOF)
{
if (n== && d== && r==) break;
for (int i= ;i<n ;i++) scanf("%d",&an[i]);
for (int i= ;i<n ;i++) scanf("%d",&bn[i]);
int ans=;
sort(an,an+n);
sort(bn,bn+n,cmp);
for (int i= ;i<n ;i++) if (an[i]+bn[i]>d) ans+=(an[i]+bn[i]-d)*r;
printf("%d\n",ans);
}
return ;
}

UVA 11389 The Bus Driver Problem 贪心水题的更多相关文章

  1. UVA 11389 The Bus Driver Problem

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82842#problem/D In a city there are n bus ...

  2. UVa 11389 - The Bus Driver Problem 难度:0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. 【策略】UVa 11389 - The Bus Driver Problem

    题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线.给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r.问如何分配路线才能使加班费最少. 虽然代码看起来 ...

  4. PAT甲题题解-1125. Chain the Ropes (25)-贪心水题

    贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...

  5. UVa 11389 (贪心) The Bus Driver Problem

    题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线. 给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r. 问如何分配路线才能使加班费最少. 分析: 感 ...

  6. The Bus Driver Problem

    题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=90648#problem/G 题意: 给每位司机分配一个白天和晚上的行车路线, ...

  7. 贪心水题。UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing

    UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { ; ){ ; ) r ...

  8. UVa(11292),贪心水题

    蓝书P1, 很简单的一个贪心选择,用能力小的去砍小的.本来想双重循环,哎,傻逼了,直接遍历选手,碰到能砍的就砍掉. #include <stdio.h> #include <algo ...

  9. UVA11389 The Bus Driver Problem

        题意:有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线.给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d*r.问如何分配路线才能使加班费最少.   贪心 ...

随机推荐

  1. python上数据存储 .h5格式或者h5py

    最近在做城市计算的项目,数据文件是以.h5的格式存储的,总结下其用法和特点 来自百度百科的简介: HDF(Hierarchical Data Format),可以存储不同类型的图像和数码数据的文件格式 ...

  2. 数据库路由中间件MyCat - 源代码篇(10)

    此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 3. 连接模块 3.5 后端连接 3.5.2 后端连接获取与维护管理 还是那之前的流程, st=>st ...

  3. WebApi 跨域

    http://www.cnblogs.com/lori/p/3557111.html http://bbs.csdn.net/topics/391020576

  4. leetcode 【 Search in Rotated Sorted Array 】python 实现

    题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7  ...

  5. leetcode 【 Two Sum 】python 实现

    题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...

  6. Vue声明渲染以及axios实例

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  7. HTML textarea 无法修改 value 的问题

    当设置了  textarea  的 value 后,发现页面的输入框无法输入值, <textarea id="></textarea> 解决方法: 只需将值设置在  ...

  8. yum 快速安装 Rabbitmq for CentOS6

    1.安装CENTOS6的系统. 2.配置源 ,说明:https://github.com/rabbitmq/erlang-rpm To use Erlang 20.x on CentOS 6: # I ...

  9. Flask-WebSocket案例

    实验1:实现初始的通信 客户端:用浏览器向服务端发送信息 服务端:首先接收浏览器发来的信息,并作出相应应答 第一步:需要导入模块: from flask import Flask,request fr ...

  10. PAT1033

    旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在2行中分别给出坏掉的那些键.以及应该输入的文 ...