sdutoj 2154 Shopping
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2154
Shopping
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
You can assume the street as a straight line, while the shops are some points on the line.
They park their car at the leftmost shop, visit all the shops from left to right, and go back to their car.
Your task is to calculate the length of their route.
输入
The first line of input in each test case contains one integer N (0<N<100001), represents the number of shops.
The next line contains N integers, describing the situation of the shops. You can assume that the situations of the shops are non-negative integer and smaller than 2^30.
The last case is followed by a line containing one zero.
输出
示例输入
4
24 13 89 37
6
7 30 41 14 39 42
0
示例输出
152
70
提示
来源
示例程序
分析:
求路径和,直接求最值差的二倍即可。
AC代码:
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[];
int main()
{
int n;
while(cin>>n&&n)
{
memset(a,,sizeof(a));
for(int i=;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
cout<<*(a[n-]-a[])<<endl;
}
return ;
}
sdutoj 2154 Shopping的更多相关文章
- sdut 2154:Shopping(第一届山东省省赛原题,水题)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- Shopping(山东省第一届ACM省赛)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- BZOJ 2154: Crash的数字表格 [莫比乌斯反演]
2154: Crash的数字表格 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 2924 Solved: 1091[Submit][Status][ ...
- 【BZOJ】2154: Crash的数字表格
http://www.lydsy.com/JudgeOnline/problem.php?id=2154 题意:求$\sum_{i=1}^{n} \sum_{j=1}^{m} lcm(i, j)$, ...
- sdutoj 2151 Phone Number
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2151 Phone Number Time Li ...
- sdutoj 2610 Boring Counting
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2610 Boring Counting Time ...
- sdutoj 2609 A-Number and B-Number
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2609 A-Number and B-Numbe ...
- sdutoj 2624 Contest Print Server
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2624 Contest Print Server ...
- sdutoj 2608 Alice and Bob
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...
随机推荐
- C++ builder的文件操作
在编程的过程中,文件的操作是一个经常用到的问题,在C++Builder中,可以使用多种方法对文件操作,下面我就按以下几个部分对此作详细介绍,就是:1.基于C的文件操作:2.基于C++的文件操作:3.基 ...
- delphi 最全日期格式_DateUtils时间单元说明
DateUtils时间单元说明 CompareDate 函数 比较两个日期时间值日期部分的大小 CompareDateTime 函数 比较两个日期时间值的大小 CompareTime 函数 比较两个日 ...
- vector 初始化所有方法
简介:vector可用于代替C中的数组,或者MFC中的CArray,从许多说明文档或者网上评论,一般一致认为应该多用vector,因为它的效率更高,而且具备很好的异常安全性.而且vector是STL推 ...
- Comparable与Comparator
转载 Comparable与Comparator的区别 (转载) Comparable & Comparator 都是用来实现集合中元素的比较.排序的,只是 Comparable 是在集合内部 ...
- Mysql 常用命令集
1.mysqlbinlog工具使用方法如下: 先使用 show binary logs 查看 在使用导出命令 mysqlbinlog -R -uroot -pxxxx -hxxx.xxx.xxx.xx ...
- ubuntu navicat
接下来是从网络上下载Chrome对应是版本的包,小编的系统是64位的,因此,执行:wget https://dl.google.com/linux/direct/google-chrome-stabl ...
- hadoop与云技术、云计算混肴澄清
本文引用自:http://www.aboutyun.com/blog-61-248.html 一.初学者问题: 请教个问题在实际的生成环境里面,数据源产生的地方部署Hadoop,还是需要程序把数据给迁 ...
- $watch、$digest、$apply
$watch.$digest.$apply $watch 代表的就是对数据源的监听,当数据源发生变化,就会触发第二个参数的回调函数 $digest 代表触发一个数据源变化的事件 $apply 代表对于 ...
- android jdbc 远程数据库
http://blog.csdn.net/conowen/article/details/7435231/
- C++ 自动指针 共享指针
#include <iostream> #include <string> #include <memory> class Item { public: Item( ...