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 ...
随机推荐
- Linux Shell编程(25)——I/O 重定向
默认情况下始终有3个"文件"处于打开状态, stdin (键盘), stdout (屏幕), and stderr (错误消息输出到屏幕上). 这3个文件和其他打开的文件都可以被重 ...
- 数据结构(并查集||树链剖分):HEOI 2016 tree
[注意事项] 为了体现增强版,题目限制和数据范围有所增强: 时间限制:1.5s 内存限制:128MB 对于15% 的数据,1<=N,Q<=1000. 对于35% 的数据,1<=N,Q ...
- 有关Spring Batch
在使用Spring Batch时,在无法实现StepListener的情况下,如何使用ExecutionContext呢. 解决办法,使用宣言@BeforeStep或@AfterStep.
- HDOJ 2030 汉字统计
Problem Description 统计给定文本文件中汉字的个数. Input 输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本. Output 对于每一段文本,输出其中的汉字的个数 ...
- mac下的改装人生——mbp拆卸的各种资源整理
这几天弄了好多的mac上硬件的问题,我自己的mac也被我拆了3次,感觉自己终于跟硬件扯上关系了哈. 在这里放一些我找到比较好的资源教程,供大家学习,如果我以后还需要继续拆我的macbook,我也会回来 ...
- xrdp远程 & watchdog 启用与测试 & WebRTC
sudo apt-get install xrdp sudo apt-get install vnc4server tightvncserver echo "xfce4-session&qu ...
- [置顶] AFNetworking 2.0 新特性讲解之AFHTTPSessionManager
AFNetworking 2.0 相比1.0 API 接口改动还是很大的. 其中一个便是 AFURLSessionManager,当然如果你不太熟悉,或者为了兼容低版本,你依然可以选择AFHTTPRe ...
- js 解析 bytearray 成 字符串
function bin2String(array) { return String.fromCharCode.apply(String, array); } var bit=[104,101,108 ...
- QT 读写sqllite数据库
QT 读写sqllite数据库 分类: 技术资料2014-04-10 10:39 84人阅读 评论(0) 收藏 举报 #include <QtGui/QApplication> #incl ...
- [转] 用管道获得shell 命令的输出
用管道: 通过fgets(buf, n, ptr)buf就可以得到命令“ps -ef"一样的信息, 读帮助”man popen": char *cmd = "ps -ef ...