SGU 158.Commuter Train
一道简单题。
火车停的位置不是在整点就是在二分之一点,坐标*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的更多相关文章
- 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 ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- 每日英语: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 ...
- (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 ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- 清华学堂 列车调度(Train)
列车调度(Train) Description Figure 1 shows the structure of a station for train dispatching. Figure 1 In ...
- Organize Your Train part II-POJ3007模拟
Organize Your Train part II Time Limit: 1000MS Memory Limit: 65536K Description RJ Freight, a Japane ...
- 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 ...
- (转) 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 ...
随机推荐
- VM Depot 镜像新增系列II – 学习管理系统,内容管理系统以及平台管理工具
发布于 2014-06-23 作者 刘 天栋 继上周企业管理软件和电子商务镜像的加盟之后,我们看到又有一批内容管理解决方案(CMS),学习管理解决方案(LMS)以及平台管理工具 (如 Open ...
- (转载)Mysql中,SQL语句长度限制
(转载)http://qjoycn.iteye.com/blog/1288435 今天发现了一个错误:Could not execute JDBC batch update 最后发现原因是SQL语句长 ...
- Delphi WebService 需要注意 转
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://gang4415.blog.51cto.com/225775/251997 Web ...
- 最大流算法---Edmond-Karp
这个算法是基于FF方法,就是通过不断求残余网络的增广路来增广流量,直到找不到增广路为止.注意:每次找到增广路以后都要更新原网络.EK算法通过BFS寻找源S到汇T的一条最短路径,因此时间复杂度是O(VE ...
- winphone 开发学习笔记(2)
导航 NavigationService.Navigate(new Uri("xxxx.xaml",UriKind.Relative)) xxx表示要跳转的目标页面 页面和页面导航 ...
- DD-WRT相关资源
版本网站下载:Other Downloads,进入betas->2014 FTP下载:如ftp://ftp.dd-wrt.com/betas/2014/06-23-2014-r24461/ Re ...
- Service的两种启动方法
刚才看到一个ppt,介绍service的两种启动方法以及两者之间的区别. startService 和 bindService startService被形容为我行我素,而bindService被形容 ...
- Java IO复习(一)
package com.zyw.file; import java.io.*; /** * Created by zyw on 2016/3/10. */ public class IOTest { ...
- [git] git 的基础功能
有两种方法获得一个 git 仓库:自行初始化,克隆别人已有的仓库 自行初始化 git init 克隆别人已有的库 git clone git@github.com:garrisonz/gitStudy ...
- Java开发中文件读取方式总结
JAVA开发中,免不了要读文件操作,读取文件,首先就需要获取文件的路径. 路径分为绝对路径和相对路径. 在文件系统中,绝对路径都是以盘符开始的,例如C:\abc\1.txt. 什么是相对路径呢?相对路 ...