一道简单题。

火车停的位置不是在整点就是在二分之一点,坐标*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. HDU-1846 Brave Game

    http://acm.hdu.edu.cn/showproblem.php?pid=1846 (一)巴什博奕(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最 ...

  2. HDOJ/HDU 1073 Online Judge(字符串处理~)

    Problem Description Ignatius is building an Online Judge, now he has worked out all the problems exc ...

  3. HDOJ 1032(POJ 1207) The 3n + 1 problem

    Description Problems in Computer Science are often classified as belonging to a certain class of pro ...

  4. 你不一定能做对的JavaScript闭包面试题

    由工作中演变而来的面试题 这是一个我工作当中的遇到的一个问题,似乎很有趣,就当做了一道题去面试,发现几乎没人能全部答对并说出原因,遂拿出来聊一聊吧. 先看题目代码: function fun(n,o) ...

  5. mongodb基本概念解析

    MongoDB 概念解析 不管我们学习什么数据库都应该学习其中的基础概念,在mongodb中基本的概念是文档.集合.数据库,下面我们挨个介绍. 下表将帮助您更容易理解Mongo中的一些概念: SQL术 ...

  6. 了解各种AA特性

    AA(Anti-Aliasing)抗锯齿想必不少玩家在游戏画质设定中经常会遇到,说通俗一点AA抗锯齿的作用:将图像边缘及其两侧的像素颜色进行混 合,然后用新生成的具有混合特性的点来替换原来位置上... ...

  7. head first-----decorate design pattern

    浅谈设计模式之------装饰者模式     首先给出装饰者模式的定义吧:              动态的将责任附加到对象上,若是要扩展功能,装饰者提供了比继承更加具有弹性的替代方案.     其中 ...

  8. OMCS的语音视频带宽占用

    OMCS的语音.视频.电子白板.远程桌面等功能对网络带宽的要求分别如何了? 我们先假设一种常见的场景:假设N个在线用户同时进行1对1的多媒体沟通(即分为N/2组),在不考虑P2P通道的情况下,带宽的大 ...

  9. 屏幕录制:SCR Screen Recorder Pro v0.14.3汉化破解版

    应用概览 <ignore_js_op> 软件名称:屏幕录制:SCR Screen Recorder Pro 软件版本:v0.14.3汉化破解版软件语言:中文软件大小:3.5M软件包名:co ...

  10. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(42)-工作流设计01

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(42)-工作流设计01 工作流在实际应用中还是比较广泛,网络中存在很多工作流的图形化插件,可以做到拉拽的工 ...