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大学生程序设计竞赛

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

水题  排序

#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#define MAX 100005
#define LL long long
using namespace std;
int main()
{
int n;
int a[MAX];
while(~scanf("%d",&n)&&n!=0){
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
LL sum=0;
for(int i=1;i<n;i++)
sum+=(a[i]-a[i-1]);
sum+=(a[n-1]-a[0]);
printf("%lld\n",sum);
}
return 0;
}

  

Shopping(山东省第一届ACM省赛)的更多相关文章

  1. Balloons(山东省第一届ACM省赛)

    Balloons Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Both Saya and Kudo like balloons ...

  2. 山东省第一届ACM省赛

      ID PID Title Accepted Submit A 2151 Phone Number 22 74 B 2159 Ivan comes again! 1 17 C 2158 Hello ...

  3. Emergency(山东省第一届ACM省赛)

    Emergency Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...

  4. 2010山东省第一届ACM程序设计竞赛

    休眠了2月了 要振作起来了!!... http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2155 因 ...

  5. sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)

    题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...

  6. sdut 2159 Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛) 线段树+离散

    先看看上一个题: 题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条 ...

  7. 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)

    题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...

  8. Hello World! 2010年山东省第一届ACM大学生程序设计竞赛

    Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...

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

    Phone Number Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that if a phone number A is anothe ...

随机推荐

  1. [读书笔记]Java之动态分派

    以下内容来自周志明的<深入理解Java虚拟机>. 前一篇说了静态分派和重载有关,现在的动态分派就和覆盖Override有关了. 先看代码: public class DynamicDisp ...

  2. 调用外部js文件测试

    test <p><img id="img" onclick="javascript:var s=document.createElement('scri ...

  3. 2016年中国大学生程序设计竞赛(合肥)-重现赛1001 HDU 5961

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  4. Android ndk另一种注册方式

    不使用Java_com_xxx方式调用ndk的方式,这种方法的优点是灵活,可配置,不必限制在Java_com_xxx命名依赖中. 步骤如下: 第1步,在JNI初始化方法中调用自定义注册方法,并判断成功 ...

  5. xml报文的装配解析

    xstream dom 将map自动转化为xml报文 http://blog.csdn.net/lisheng19870305/article/details/45847985 报文的通信

  6. Lua简介

    Lua是一种扩展语言,脚本语言,还没有主程序的概念,类似于插件,也即不能直接使用,必须嵌入在牛逼的语言里使用,如Python. Lua由C语言编写,可以在宿主语言里写一段c程序,让Lua的解释器使用, ...

  7. Vigenère密码

    来源  NOIP2012复赛 提高组 第一题 描述 16世纪法国外交家Blaise de Vigenère设计了一种多表密码加密算法--Vigenère密码.Vigenère密码的加密解密算法简单易用 ...

  8. 关于eclipse保存代码很慢,提示the user operation is waiting的问题

    关于eclipse保存代码很慢,提示the user operation is waiting的问题 首先 去掉 project - build Automaticlly 然后 project-> ...

  9. kylin(一): 原理架构

    由eBay开源的一个大数据OLAP框架,2014年11月加入了Apache,项目名字也改成了"Apache Kylin",Apache Kylin是唯一来自中国的Apache顶级开 ...

  10. web异常流量定位:iftop+tcpdump+wireshark

    一个简单的运维小经验. 场景:web服务器出现异常流量,web集群内部交互出现大流量,需要定位具体的http请求,以便解决问题. 目的:找出产生大流量的具体http请求. 工具:        ift ...