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. SEO如何辨别真假Baiduspider

    我们站长查看网站访问数据,分析IP来源是我们站长的日常工作,对一些异常的IP段,我们首先要区分是否是搜索引擎蜘蛛的IP段,以免误伤,下面我们就以2段IP为例,一个是百度蜘蛛的220.181.108.1 ...

  2. 微信开发03----------XML解析与封装

    3.1 解析微信发来的请求  微信服务器发来的请求消息都被封装在request对象中,可以从request对象中将请求参数取出来.通常是用request的getParament()方法获取请求中的参数 ...

  3. HDU 1285 确定比赛排名 (数组实现 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    ...

  4. AJAX跨域

    AJAX跨域AJAX不允许跨域访问. 跨域是指浏览器B显示的是服务器S1的数据,全是从S1取得的数据则是同域:但如果B显示的S1上的数据的某个比如img是从S2上取得的数据,则是跨域.端口不一样也是跨 ...

  5. java数组引用

    public class Arriy { public static void main(String args[]){ int data[]=new int[3]; data[0]=10; data ...

  6. Maven安装最佳实践(Windows平台)

    第一步:下载maven,解压缩. 在maven官网下载maven文件,这里我下载的是"apache-maven-2.2.1-bin.zip",如果需要maven的源代码,可以选择下 ...

  7. nginx入门篇----nginx服务器基础配置

    1.nginx.conf文件结构...                         #全局块  events{  ...  }  http                      #http块{ ...

  8. nginx入门篇----安装、部署、升级

    1.安装前准备工作下载nginx安装包依赖包:gcc pcre pcre-level  zlib zlib-devel openssl openss-level在线依赖包安装命令:yum -y ins ...

  9. #mysql:command not found

    一.问题描述 1.在linux中已经安装好mysql,通过#ps -ef |grep mysql 能显示mysql已经启动,但去进入mysql命令页面出现如下问题: [root@root ~]# my ...

  10. kali-dmitry 域名信息收集

    DMirty:用来收集以下信息: 1. 端口扫描 2. whois主机IP和域名信息 3. 从Netcraft.com获取主机信息 4. 子域名 5. 域名中包含的邮件地址 1.使用方法: Deepm ...