http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2154

Shopping

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

Saya and Kudo go shopping together.
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 input consists of several test cases.
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.

输出

 For each test case, print the length of their shopping route.

示例输入

4
24 13 89 37
6
7 30 41 14 39 42
0

示例输出

152
70

提示

Explanation for the first sample: They park their car at shop 13; go to shop 24, 37 and 89 and finally return to shop 13. The total length is (24-13) + (37-24) + (89-37) + (89-13) = 152

来源

 2010年山东省第一届ACM大学生程序设计竞赛

示例程序

分析:

求路径和,直接求最值差的二倍即可。

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的更多相关文章

  1. sdut 2154:Shopping(第一届山东省省赛原题,水题)

    Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...

  2. Shopping(山东省第一届ACM省赛)

    Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...

  3. BZOJ 2154: Crash的数字表格 [莫比乌斯反演]

    2154: Crash的数字表格 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 2924  Solved: 1091[Submit][Status][ ...

  4. 【BZOJ】2154: Crash的数字表格

    http://www.lydsy.com/JudgeOnline/problem.php?id=2154 题意:求$\sum_{i=1}^{n} \sum_{j=1}^{m} lcm(i, j)$, ...

  5. sdutoj 2151 Phone Number

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2151 Phone Number Time Li ...

  6. sdutoj 2610 Boring Counting

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2610 Boring Counting Time ...

  7. sdutoj 2609 A-Number and B-Number

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2609 A-Number and B-Numbe ...

  8. sdutoj 2624 Contest Print Server

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2624 Contest Print Server ...

  9. sdutoj 2608 Alice and Bob

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...

随机推荐

  1. strcpy 和 strnpy 区别

    与strncpy的区别 第一种情况: 1 2 3 4     char* p="how are you ?";         char name[20]="ABCDEF ...

  2. Qt StyleSheet皮肤(黑色,比较好看,而且很全)

    使用方式如下 //设置皮肤样式 static void SetStyle(const QString &styleName) { QFile file(QString(":/imag ...

  3. Delphi Memory-Mapped File简单示例

    { Copyright ?1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira } unit MainFrm; ...

  4. HTML与CSS的关系

    1. HTML是网页内容的载体.内容就是网页制作者放在页面上想要让用户浏览的信息,可以包含文字.图片.视频等. 2. CSS样式是表现.就像网页的外衣.比如,标题字体.颜色变化,或为标题加入背景图片. ...

  5. jquery.autocomplete.js 插件的自定义搜索规则

    这二天开始用jquery.autocomplete这个自动完成插件.功能基本比较强大,但自己在实际需求中发现还是有一处不足!问题是这样:当我定义了一个本地数据JS文件时,格式为JSON式的数组.如下: ...

  6. Rails进阶参考

    https://gist.github.com/xdite/4044f3a037de029bc35c From idea to products: - Ideation, wireframes, mo ...

  7. Tomcat 处理请求时的中文乱码问题

    利用Tomcat8作为服务器,采用servlet接收前端请求后进行处理的过程中,前台请求中有中文时,中文信息变成了乱码. 经过调试和查阅,发现Tomcat在处理get请求和post请求是有区别的.参照 ...

  8. gulp教程

    1. http://www.tuicool.com/articles/FJVNZf 2.http://www.ydcss.com/archives/18 3.手动创建package.json: 如:c ...

  9. iOS UIApplicationDelegate

    1.- (void)applicationWillResignActive:(UIApplication *)application说明:当应用程序将要入非活动状态执行,在此期间,应用程序不接收消息或 ...

  10. Basic motion detection and tracking with Python and OpenCV

    http://www.pyimagesearch.com/2015/05/25/basic-motion-detection-and-tracking-with-python-and-opencv/