一道简单题。

火车停的位置不是在整点就是在二分之一点,坐标*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. Linux Shell编程(21)——复杂命令

    更高级的用户命令find-exec COMMAND \;在每一个find 匹配到的文件执行 COMMAND 命令. 命令序列以 ; 结束( ";" 是 转义符 以保证 shell ...

  2. 查找IP来源

    通过调用淘宝IP库获取IP归属地,脚本如下: #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib import json impor ...

  3. Google Map API 学习2-界面展示

  4. Spark RCFile的那些“坑”

    RCFile在平台的应用场景中多数用于存储需要“长期留存”的数据文件,在我们的实践过程中,RCFile的数据压缩比通常可以达到8 : 1或者10 : 1,特别适用于存储用户通过Hive(MapRedu ...

  5. Web Services的相关名词解释:WSDL与SOAP

    在对Web Services进行性能测试时,接触到最多的两个名词就是WSDL和SOAP.利用LoadRunner对Web Services进行调用的时候,也存在两种常用方法,即基于WSDL的[Add ...

  6. unity3d Realistic eye shading 真实的眼睛渲染

    先放上效果 人皮都做了,当然要来研究下眼睛,眼睛要比人体皮肤简单一些(实时模拟人皮在此) 一看是不是很复杂 这是眼睛的解构,但是,我们只需要模拟出虹膜巩膜和角膜就能达到相当真实的眼睛 巩膜就是白眼球 ...

  7. 关于响应事件中的Sender

    很多响应事件都会有个参数就是Sender,如下: - (IBAction)updateSliderValue:(id)sender Sender其实就是触发响应的那个实例对象,比如这个消息是由一个UI ...

  8. 模糊化GPU滤镜汇总

    GPUImageTiltShiftFilter 这是一个模糊图片上下两层的滤镜效果,可以调节模糊边界,可以调节模糊程度 总共4个参数,具体如下     //模糊度的调节,0为最清晰,后面越来越模糊   ...

  9. Java Executor 框架学习总结

    大多数并发都是通过任务执行的方式来实现的.一般有两种方式执行任务:串行和并行. class SingleThreadWebServer { public static void main(String ...

  10. CMDLINE的解析

    在linux的config文件中有一个特殊的宏定义CMDLINE,以前也一直在使用这个宏的参数,但是真正这个宏的解析和使用却不怎么明确.这次有机会多对它有些了解,不妨把这个浅显的认识说出来,记下来. ...