sdut 2154:Shopping(第一届山东省省赛原题,水题)
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
提示
来源
水题,最大值减最小值的差乘以二就是结果。
代码:
#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(第一届山东省省赛原题,水题)的更多相关文章
- sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)
Ivan comes again! Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 The Fairy Ivan gave Say ...
- sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)
Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...
- sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
Clockwise Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...
- sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)
Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...
- sdut 2163:Identifiers(第二届山东省省赛原题,水题)
Identifiers Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Identifier is an important c ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- sdut 2165:Crack Mathmen(第二届山东省省赛原题,数论)
Crack Mathmen Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Since mathmen take securit ...
- 第一届山东省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 ...
- 第一届山东省ACM——Balloons(java)
Description Both Saya and Kudo like balloons. One day, they heard that in the central park, there wi ...
随机推荐
- OpenERP函數字段的應用
在ERP開發過程中經常會使用到某字段的值是由其他字段計算得來,並且有些還需要將計算的結果存入資料庫. 以上功能上OpenERP中是用field.function實現的 其中有種模式 a). 只計算,不 ...
- ACE中TASK架构简介及简单应用
一.基础功能介绍 1.ACE_Message_Block*,Windows消息用MSG结构表示,ACE_Task中因为不能预计各种应用中消息的类型,所以ACE_Message_Block基本上可以理解 ...
- STRUTS2配置动态页面
STRUTS2配置动态页面 CreateTime--2017年5月11日09:00:31Author:Marydon 1.struts配置 <?xml version="1.0&q ...
- c++实现医院检验科排班程序
c++实现医院检验科排班程序 1.背景: 医院急诊检验科24h×7×365值班.工作人员固定.採取轮班制度.确保24h都有人值班. 本文就通过C++实现编敲代码自己主动排班,并能够转为Excel打印. ...
- Column count of mysql.user is wrong. Expected 43, found 42. Created with MySQL 50518, now running 50641. Please use mysql_upgrade to fix this error.
出现问题: Column count of mysql.user is wrong. Expected 43, found 42. Created with MySQL 50518, now runn ...
- java反射详解及说明
首先写一个Person类: package lltse.base.reflectdemo; public class Person { private String name ="张三&qu ...
- nodejs 发起http请求
http://nodejs.cn/api/http.html#http_http_request_options_callback http://yijiebuyi.com/blog/8221eb14 ...
- linux下利用shell脚本和mysqldump热备份和恢复mysql
对mifeng数据库进行每周六3:33完全热备份,并可以完全恢复! 一.先建立备份脚本 #vi /mifengbackup/backup.sh #!bin/bash cd /mifengbackup ...
- C union共用体
共用体是一种特殊的数据类型,允许您在相同的内存位置存储不同的数据类型.您可以定义一个带有多成员的共用体,但是任何时候只能有一个成员带有值.共用体提供了一种使用相同的内存位置的有效方式. 共用体定义: ...
- Android_WebServices_源代码分析
本博文为子墨原创,转载请注明出处! http://blog.csdn.net/zimo2013/article/details/38037989 在Android_WebServices_介绍一文中, ...