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

  水题,最大值减最小值的差乘以二就是结果。

  代码:

 #include <iostream>
#include <stdio.h>
using namespace std; int main()
{
int n;
int a[];
while(scanf("%d",&n)!=EOF){
if(n==) break;
long long Max=,Min=;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]>Max) //找到最大值
Max = a[i];
if(a[i]<Min) //找到最小值
Min = a[i];
}
long long sum =(Max-Min)*;
cout<<sum<<endl;
} return ;
}

Freecode : www.cnblogs.com/yym2013

sdut 2154:Shopping(第一届山东省省赛原题,水题)的更多相关文章

  1. sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)

    Ivan comes again! Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 The Fairy Ivan gave Say ...

  2. sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)

    Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...

  3. sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)

    Clockwise Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...

  4. sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)

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

  5. sdut 2163:Identifiers(第二届山东省省赛原题,水题)

    Identifiers Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  Identifier is an important c ...

  6. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  7. sdut 2165:Crack Mathmen(第二届山东省省赛原题,数论)

    Crack Mathmen Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  Since mathmen take securit ...

  8. 第一届山东省ACM——Phone Number(java)

    Description We know that if a phone number A is another phone number B’s prefix, B is not able to be ...

  9. 第一届山东省ACM——Balloons(java)

    Description Both Saya and Kudo like balloons. One day, they heard that in the central park, there wi ...

随机推荐

  1. 霍炬:再谈百度:KPI、无人机,以及一个必须给父母看的案例

    作者:霍炬.  原文链接:http://www.donews.com/idonews/article/8147.shtm 没想到我之前的一篇关于百度的文章引起了这么大的反馈. 非常多朋友称赞我写的好, ...

  2. mybatis常用标签

    1. 定义sql语句 1.1 select 标签 属性介绍: id :唯一的标识符. parameterType:传给此语句的参数的全路径名或别名 例:com.test.poso.User或user ...

  3. HttpSession 和URLRewriting

    在上面使用Cookie技术存储会话信息的时候发现Cookie存储的数据有限,而且每次需要客户端浏览器携带数据,导致网络的负载过大.因此如果需要存储相对大量的数据,那么可以直接将数据存储在服务器端,这样 ...

  4. js 将网页生成为html保存访问

    2012-04-03 今天实现了一个需求,主题是将浏览中的网页生成html保存起来,记录访问url,挂在公司网站上做案例.     首先忙活了N久的是去搜索生成html的js函数.   什么IE自带的 ...

  5. mysql的rand函数

    项目中需要动态随机生成一些固定位数的随机数,如8位,5位等. 之前看到的写法是这样 ROUND(ROUND(RAND(),5)*100000) 这样写不太准确,有几率出现4位的情况,Rand() 函数 ...

  6. static 成员变量、static 成员函数、类/对象的大小

    一.static 成员变量 对于特定类型的全体对象而言,有时候可能需要访问一个全局的变量.比如说统计某种类型对象已创建的数量. 如果我们用全局变量会破坏数据的封装,一般的用户代码都可以修改这个全局变量 ...

  7. Spring注解@ResponseBody,@RequestBody

    @RequestBody 将HTTP请求正文转换为适合的HttpMessageConverter对象. @ResponseBody 将内容或对象作为 HTTP 响应正文返回,并调用适合HttpMess ...

  8. python实现dict版图遍历

    python实现dict版图遍历的示例. 代码: #_*_coding:utf_8_import sysimport osclass Graph(): def __init__(self, V, E) ...

  9. 0x01 译文:Windows桌面应用Win32开发简介

    本节课将简单介绍下使用C++开发Windows桌面应用的一些基础知识 目录: 准备你的开发环境 Windows 代码规范 操作字符串 什么是一个Window? WinMain:程序的入口点 1. 准备 ...

  10. [svc]后台运行程序screen or nohup

    后台运行 方法1 & 方法2:screen screen –S lnmp à起个名字 进去后运行程序 Ctrl+ad à退出lnmp屏幕 Scree –ls à查看 Screen –r xxx ...