Shopping(山东省第一届ACM省赛)
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
提示
来源
链接: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省赛)的更多相关文章
- Balloons(山东省第一届ACM省赛)
Balloons Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Both Saya and Kudo like balloons ...
- 山东省第一届ACM省赛
ID PID Title Accepted Submit A 2151 Phone Number 22 74 B 2159 Ivan comes again! 1 17 C 2158 Hello ...
- Emergency(山东省第一届ACM省赛)
Emergency Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...
- 2010山东省第一届ACM程序设计竞赛
休眠了2月了 要振作起来了!!... http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2155 因 ...
- sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)
题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...
- sdut 2159 Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛) 线段树+离散
先看看上一个题: 题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条 ...
- 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)
题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...
- Hello World! 2010年山东省第一届ACM大学生程序设计竞赛
Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...
- Phone Number 2010年山东省第一届ACM大学生程序设计竞赛
Phone Number Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that if a phone number A is anothe ...
随机推荐
- php 删除一段字符串的中的中文
<?php header('Content-type:text/html;charset=utf-8'); function p($arr){ echo "<pre>&qu ...
- C#编程语言与面向对象—— 多态
多态编程的基本原理是: 使用基类或接口变量编程. 在多态编程中,基类一般都是抽象类,其中拥有一个或多个抽象方法,各个子类可以根据需要重写这些方法.或者使用接口,每个接口都规定了一个或多个抽象方法,实现 ...
- Log4j的简要概述
读取配置文件的三种使用方式: 1.Java代码:BasicConfigurator.configure() 2.Java特性:键值对解析(properties文件) PropertyConfigura ...
- 实现TCP、UDP相互通信及应用
实验名称 Socket编程综合实验(1) 一.实验目的: 1.理解进程通信的原理及通信过程 2.掌握基于TCP和UDP的工作原理 3.掌握基本的Socket网络编程原理及方法 二.实验内容 1.掌握 ...
- ipython安装
sudo pip install jupyter 然后用jupyter notebook来运行
- Roslyn 学习笔记(一)
本文记录了Roslyn开发环境的安装与编译过程,参考了以下Roslyn项目的官方文档 https://github.com/dotnet/roslyn/blob/master/docs/contrib ...
- 基于OpenCV 的iOS开发
1.创建项目 2.https://sourceforge.net/projects/opencvlibrary/files/opencv-ios/2.4.13/opencv2.framework.zi ...
- 网页中插入视频(object)
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://down ...
- springMVC 返回json 忽略类中属性的注解
该注解使用在 类名,接口头上 @JsonIgnoreProperties(value={"comid"}) //希望动态过滤掉的属性 该注解使用在get方法头上 @JsonIgno ...
- 【转载】ANSYS完全法与模态叠加法瞬态分析实例
原文地址:http://www.caetecc.com/thread-2172-1-1.html ! 半脉冲载荷 --- 模态叠加法fini/clear,nostart/PREP7ET,1,BEAM4 ...