出租车(taxi)

题目描述

Bessie在农场上为其他奶牛提供出租车服务。这些奶牛已经在沿着长度为M(1<= M <= 1,000,000,000)的栅栏上不同的地点聚集等候。不幸的是,他们已经厌倦了他们当前所在的位置并且每只奶牛都想要沿着栅栏去别的地方走走。 Bessie必须赶到这些奶牛的起始位置,并把他们带到它们的目的地。Bessie的车很小,所以她只能一次只能搭载一头奶牛。奶牛可以在同一时刻完成上车和下车。

为了节省燃气,Bessie想以尽可能少的燃料完成这次任务。N只奶牛的起始位置和结束为止都是已知的(1 <= N <=100000),请确定Bessie的最少行程。Bessie意识到,要使所得到的行程最短,Bessie可能将在沿途中让奶牛上车或下车而并不一定将一头奶牛从起点直接送到中点。

Bessie的起点是围栏的最左端,位置记为0。终点在篱笆的最右边,位置记为M。

Bessie is running a taxi service for the other cows on the farm. The cows have been gathering at different locations along a fence of length M (1 <= M <= 1,000,000,000). Unfortunately, they have grown bored with their current locations and each wish to go somewhere else along the fence. Bessie must pick up each of her friends at their starting positions and drive them to their destinations. Bessie's car is small so she can only transport one cow in her car at a time. Cows can enter and exit the car instantaneously. To save gas, Bessie would like to minimize the amount she has to drive. Given the starting and ending positions of each of the N cows (1 <= N <= 100,000), determine the least amount of driving Bessie has to do. Bessie realizes that to save the most gas she may need to occasionally drop a cow off at a position other than her destination. Bessie starts at the leftmost point of the fence, position 0, and must finish her journey at the rightmost point on the fence, position M.

输入

从文件taxi.in中输入数据

第1行:两个整数 N和M。

第2...N+1行:第(i+1)行包含两个整数,s_i和t_i(0<=s_i,t_i<=M),表示第i只奶牛的起始位置和目的地位置。

* Line 1: N and M separated by a space.

* Lines 2..1+N: The (i+1)th line contains two space separated integers, s_i and t_i (0 <= s_i, t_i <= M), indicating the

INPUT DETAILS: There are two cows waiting to be transported along a fence of length 10. The first cow wants to go from position 0 (where Bessie starts) to position

输出

输出到文件taxi.out中

输出仅一行,包含一个整数,表示Bessie所需的最短行程(这个行程不一定能用32bit的整型储存)。

* Line 1: A single integer indicating the total amount of driving

Bessie must do. Note that the result may not fit into a 32 bit

integer.

OUTPUT DETAILS: Bessie picks up the first cow at position 0 and drives to position 6.

There she drops off the first cow, delivers the second cow to her

destination and returns to pick up the first cow. She drops off the first

cow and then drives the remainder of the way to the right side of the fence.

样例输入

2 10
0 9
6 5

样例输出

12

solution

首先我们一定要走的是每段路程(硬性)

可以用方案改变的为跑空车的路程

那么问题就是怎么跑空车最优

把S,T从小到大排序,加一条m->1的路(bessie 1开始m结束)

每次从ti走到si一定最优

思路来自神犇https://oi.men.ci/bzoj-3062/

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 100005
using namespace std;
int n,m,s[maxn],t[maxn];
long long ans;
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++){
scanf("%d%d",&s[i],&t[i]);
ans=ans+abs(s[i]-t[i]);
}
s[0]=m;t[0]=0;
sort(s,s+n+1);sort(t,t+n+1);
for(int i=0;i<=n;i++){
ans=ans+abs(s[i]-t[i]);
}
cout<<ans<<endl;
return 0;
}

出租车(taxi)的更多相关文章

  1. [USACO13FEB]出租车Taxi

    洛谷题目链接:[USACO13FEB]出租车Taxi 题目描述 Bessie is running a taxi service for the other cows on the farm. The ...

  2. P3076 [USACO13FEB]出租车Taxi

    题目描述 Bessie is running a taxi service for the other cows on the farm. The cows have been gathering a ...

  3. OO Summary Ⅱ

    [第五次作业——多线程电梯] 类图 度量 协作图 设计分析: 多线程电梯是我第一次接触多线程,因此真的是无(瞎)从(g)下(2)手(写),感觉仿佛只是用一个调度器来调度3部电梯但又总觉得好像哪里不太对 ...

  4. English-旅游英语及情景对话

    1.旅游英语:预订机票情景对话及常用句型 目前,越来越多的人都选择以飞机为出行方式.但是如何用一口流利的英语订机票呢?这里我们替你总结了一些情景对话,还有一些常用的句型.大家都来学一学吧~A:Good ...

  5. 【HDU1960】Taxi Cab Scheme(最小路径覆盖)

    Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. A cost-effective recommender system for taxi drivers

    一个针对出租车司机有效花费的推荐系统 摘要 GPS技术和新形式的城市地理学改变了手机服务的形式.比如说,丰富的出租车GPS轨迹使得出做租车领域有新方法.事实上,最近很多工作是在使用出租车GPS轨迹数据 ...

  7. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  8. [ACM_数学] Taxi Fare [新旧出租车费差 水 分段函数]

    Description Last September, Hangzhou raised the taxi fares. The original flag-down fare in Hangzhou ...

  9. poj 2060 Taxi Cab Scheme (最小路径覆盖)

    http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submi ...

随机推荐

  1. 前端安全之XSS和csrf攻击

    1.Csrf攻击概念: csrf攻击(Cross-site request forgery):跨站请求伪造; 2.Csrf攻击原理: 用户是网站A的注册用户,且登录进去,于是网站A就给用户下发cook ...

  2. 自动生成 WebApi 在线说明文档。

    1.使用Swashbuckle实现 Swashbuckle 是.NET类库,可以将WebAPI所有开放的控制器方法生成对应SwaggerUI的JSON配置.再通过SwaggerUI 显示出来.类库中已 ...

  3. oracle用户创建及权限设置(转)

    权限: create session create table unlimited tablespace connect resource dba 例: #sqlplus /nolog SQL> ...

  4. vbs自由选择启动bat文件

    1.首先创建一个文件夹用来放bat文件和配置文件. 2.然后在bat文件中写入启动程序.中间红色框是启动程序,外面程序是用来隐藏命令提示符的. 3.txt配置文件配置vbs启动项,vbs只能找到此文件 ...

  5. jeesite项目

    1,登录页面.最高权限管理员 用户名:thinkgem  密码:admin 2,登陆之后展示的首页 3,分为不同的模块,由不同的入负责,我负责日志管理 已完成功能:模糊查询,分页,导入,导出Excel ...

  6. 前端开发APP,从HBuilder开始~

    内容简介 介绍目前前端人员开发app的几种方法,具体介绍hbuilder开发app,一扇赞新的大门~ 无所不能的js 最开始js仅仅局限于网页上一些效果,操作网页内容等, 但是nodejs把js带入了 ...

  7. 基于Qt Creator实现中国象棋人机对战, c++实现

    GitHub地址: https://github.com/daleyzou/wobuku 这是自己大一学完c++后,在课程实践中写过的一个程序,实现象棋人机对战的算法还是有点难的, 自己当时差不多也是 ...

  8. Java - 网络

    要事为先,你如果想要在这个行业发展下去的话,实际上三角形的三个点在支撑着你发展,一个是技术.一个是管理(不是说管理别人,是管理你自己的时间,管理你自己的精力).还有一个就是沟通,注重这三点均衡的发展. ...

  9. oracle一些常用的数据类型

    字符数据类型 char数据类型 当需要固定长度时,使用char数据类型,此数据类型长度可以使1-2000字节.若是不指定大小默认占1字节,如果长度有空余时会以空格进行填充,如果大于设定长度 数据库则会 ...

  10. Android 性能篇 -- 带你领略Android内存泄漏的前世今生

    基础了解 什么是内存泄漏? 内存泄漏是当程序不再使用到的内存时,释放内存失败而产生了无用的内存消耗.内存泄漏并不是指物理上的内存消失,这里的内存泄漏是指由程序分配的内存但是由于程序逻辑错误而导致程序失 ...