一道简单题。

火车停的位置不是在整点就是在二分之一点,坐标*2,然后枚举火车停的位置,计算总距离即可。

code:

#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#define INF 309
using namespace std;
int L, m, n, x, ans, p;
int pg[INF], train[INF];
int main() {
cin >> L >> m;
for (int i = 1; i <= m; i++) cin >> x, pg[i] = x << 1;
cin >> n;
for (int i = 2; i <= n; i++) cin >> x, train[i] = x << 1;
L <<= 1;
for (int s = 0; train[n] <= L;) {
int tem = 0;
for (int i = 1; i <= m; i++) {
int t = lower_bound (train + 1, train + 1 + n, pg[i]) - train;
if(t!=1)tem += min (abs (train[t]-pg[i]), abs (train[t - 1] - pg[i]) );
else
tem+=abs(train[t]-pg[i]);
}
if (ans < tem)
ans = tem, p = s;
for (int i = n; i >= 1; i--)
train[i]++;
s++;
}
cout<<p/2;if(p&1) cout<<".5";
cout<<' '<<ans/2;if(ans&1) cout<<".5";
return 0;
}

  

SGU 158.Commuter Train的更多相关文章

  1. A planning attack on a commuter train carriage in Taipei

    Last night an explosion on a commuter train carriage in Taipei Songshan railway station wounded at l ...

  2. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  3. 每日英语:Are Smartphones Turning Us Into Bad Samaritans?

    In late September, on a crowded commuter train in San Francisco, a man shot and killed 20-year-old s ...

  4. (zhuan) How to Train Neural Networks With Backpropagation

    this blog from: http://blog.demofox.org/2017/03/09/how-to-train-neural-networks-with-backpropagation ...

  5. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  6. 清华学堂 列车调度(Train)

    列车调度(Train) Description Figure 1 shows the structure of a station for train dispatching. Figure 1 In ...

  7. Organize Your Train part II-POJ3007模拟

    Organize Your Train part II Time Limit: 1000MS Memory Limit: 65536K Description RJ Freight, a Japane ...

  8. The last packet successfully received from the server was 2,926,157 milliseconds ago. The last packet sent successfully to the server was 2,926,158 milliseconds ago. is longer than the server configured value of 'wait_timeout'. 解决办法

    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully rec ...

  9. (转) How to Train a GAN? Tips and tricks to make GANs work

    How to Train a GAN? Tips and tricks to make GANs work 转自:https://github.com/soumith/ganhacks While r ...

随机推荐

  1. 原生javascript难点总结(1)---面向对象分析以及带来的思考

    ------*本文默认读者已有面向对象语言(OOP)的基础*------ 我们都知道在面向对象语言有三个基本特征 :  封装 ,继承 ,多态.而js初学者一般会觉得js同其他类C语言一样,有类似于Cl ...

  2. Unity3D屠龙战机项目总结

    之前跟着老师后面边学边做了一个屠龙战机项目,在这个项目中,主要用到的技术,在这里总结一下(本次项目的脚本语言用的是JS): 1.  如果想在场景中导入一个声音文件,则需要在脚本中添加一个变量,如在脚本 ...

  3. maya绝招(21--40)

    第21招 将Outliner分成两个 在该视图中如果元素很多的时候,会觉得Outliner不够用,这个时候拖动下侧的底框,就可以分成两栏,这样选择就省事多了. 第22招 运用选择区域,快速选择物体 在 ...

  4. poj 3159 Candies

    Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 25776   Accepted: 7033 Descrip ...

  5. list去除重复

    1. [代码][Python]代码 简单去重      ? 1 2 3 4 5 l = [1,2,3,3] l = list(set(l))   >>>l >>>[ ...

  6. UVa1607 poj1435 UVaLive1686 Gates

    填坑系列(p.246) 由函数连续性得满足二分性 #include<cstdio> #include<cstring> #include<cstdlib> #inc ...

  7. jquery 实现页面拖拽并保存到cookie

    实现的效果就是页面内的图片可拖拽到任意位置,并将所在位置保存.下次打开页面依然可见.本文是作demo用,实际开发中,位置的数据应保存到数据库中. 好了,开始. 1.准备工作. a.jquery(1.7 ...

  8. mybatis0206 延迟加载

    延迟加载 1.1使用延迟加载意义 在进行数据查询时,为了提高数据库查询性能,尽量使用单表查询,因为单表查询比多表关联查询速度要快. 如果查询单表就可以满足需求,一开始先查询单表,当需要关联信息时,再关 ...

  9. Java读取WEB-INF目录下的properties配置文件

    如何在Java代码中读取WEB-INF目录下的properties配置文件,下文给出了一个解决方案. 我们习惯将一些配置信息写在配置文件中,比如将数据库的配置信息URL.User和Password写在 ...

  10. [转] React同构思想

    React比较吸引我的地方在于其客户端-服务端同构特性,服务端-客户端可复用组件,本文来简单介绍下这一架构思想. 出于篇幅原因,本文不会介绍React基础,所以,如果你还不清楚React的state/ ...