The Fair Nut and Elevator
 

 
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The Fair Nut lives in nn story house. aiai people live on the ii-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening.

It was decided that elevator, when it is not used, will stay on the xx-th floor, but xx hasn't been chosen yet. When a person needs to get from floor aa to floor bb, elevator follows the simple algorithm:

  • Moves from the xx-th floor (initially it stays on the xx-th floor) to the aa-th and takes the passenger.
  • Moves from the aa-th floor to the bb-th floor and lets out the passenger (if aa equals bb, elevator just opens and closes the doors, but stillcomes to the floor from the xx-th floor).
  • Moves from the bb-th floor back to the xx-th.

The elevator never transposes more than one person and always goes back to the floor xx before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the aa-th floor to the bb-th floor requires |a−b||a−b|units of electricity.

Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the xx-th floor. Don't forget than elevator initially stays on the xx-th floor.

Input

The first line contains one integer nn (1≤n≤1001≤n≤100) — the number of floors.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1000≤ai≤100) — the number of people on each floor.

Output

In a single line, print the answer to the problem — the minimum number of electricity units.

Examples
input

Copy
3
0 2 1
output

Copy
16
input

Copy
2
1 1
output

Copy
4
Note

In the first example, the answer can be achieved by choosing the second floor as the xx-th floor. Each person from the second floor (there are two of them) would spend 44 units of electricity per day (22 to get down and 22 to get up), and one person from the third would spend 88units of electricity per day (44 to get down and 44 to get up). 4⋅2+8⋅1=164⋅2+8⋅1=16.

In the second example, the answer can be achieved by choosing the first floor as the xx-th floor.

题目来源:http://codeforces.com/problemset/problem/1084/A

其实,这个题目只要理解清楚意思很好写。

题目大意是说:在一个n层的大楼里的住户每天要上下楼各一次,电梯每移动一层消耗一点电能,求:最少需要消耗的电能。

首先,要清楚题目中的第x层是一个未知的楼层。也就是说,需要找到最优的第x层得出最后的答案。有了这样的思路,题目就很好写了。

其次,注意题目本意是第x层需要返回。也就是说,每次执行上下楼层后都要返回第x层。

最后,话就不多说了,暴力可以解决的问题从来不是问题,如果是问题,那就是不够暴力。代码如下:

#include<stdio.h>
#include<algorithm>
using namespace std; int main()
{
int a[];//存各楼层人数
int n;//楼层数
long long sum,ans=0x3f3f3f3f;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<=n;i++)//改变x的值
{
sum=;
for(int j=;j<=n;j++)
{
sum+=(abs(j-i)+abs(i-)+abs(j-))**a[j];//各次上下楼层消耗电量的和
}
ans=min(sum,ans);//找出最优的答案
}
printf("%ld\n",ans);
return ;
}

感觉好水。。。

电梯问题——致敬ACM的更多相关文章

  1. 楼天城楼教主的acm心路历程(作为励志用)

    楼主个人博客:小杰博客 利用假期空暇之时,将这几年GCJ,ACM,TopCoder 參加的一些重要比赛作个 回顾.昨天是GCJ2006 的回顾,今天时间上更早一些吧,我如今还清晰记得3 年 前,我刚刚 ...

  2. 【转】楼天城楼教主的acm心路历程(作为励志用)

    利用假期空闲之时,将这几年GCJ,ACM,TopCoder 参加的一些重要比赛作个回顾.昨天是GCJ2006 的回忆,今天时间上更早一些吧,我现在还清晰记得3 年前,我刚刚参加ACM 时参加北京赛区2 ...

  3. 剪辑的楼天城的ACM之路

    楼天城楼教主的acm心路历程(剪辑) 利用假期空闲之时,将这几年GCJ,ACM,TopCoder 参加的一些重要比赛作个回顾.昨天是GCJ2006 的回忆,今天时间上更早一些吧,我现在还清晰记得3 年 ...

  4. 楼塔当天领袖acm心理(作为励志使用)

    楼主个人博客:吉尔博客 假期空闲的时候使用.这些年来GCJ.ACM,TopCoder 的一个号码的一重要的比赛的参与 回顾.GCJ2006 的回顾,今天时间上更早一些吧,我如今还清晰记得3 年 前.我 ...

  5. 2013腾讯编程马拉松||HDU 4505 小Q系列故事——电梯里的爱情 水水水

    http://acm.hdu.edu.cn/showproblem.php?pid=4505 题目大意: 电梯最开始在0层,并且最后必须再回到0层才算一趟任务结束.假设在开始的时候已知电梯内的每个人要 ...

  6. SCNU ACM 2016新生赛决赛 解题报告

    新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...

  7. SCNU ACM 2016新生赛初赛 解题报告

    新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...

  8. acm结束了

    最后一场比赛打完了.之前为了记录一些题目,开了这个博客,现在结束了acm,这个博客之后也不再更新了. 大家继续加油!

  9. 关于ACM的总结

    看了不少大神的退役帖,今天终于要本弱装一波逼祭奠一下我关于ACM的回忆. 从大二上开始接触到大三下结束,接近两年的时间,对于大神们来说两年的确算不上时间,然而对于本弱来说就是大学的一半时光.大一的懵懂 ...

随机推荐

  1. radhat6.6上安装oracle12c RAC (三)

    三.DB(database)安装 3.1 DB软件安装 orale用户登录,解压db安装包 [root@jydb1 tools]# su - oracle [oracle@jydb1 ~]$ cd / ...

  2. 基础JAVA程序设计(多个类与方法的实现2)

    设计一个类代表二维空间的一个点(Point),要求:两个成员变量:x坐标和y坐标. 设计一个类代表二维空间的一个圆(Circle),要求:两个成员变量:一个是圆心,一个是半径:提供计算圆面积的方法:提 ...

  3. FL Studio中的音频设置

    在FL Studio中,有一步很关键的设置需要我们详细熟悉了解,它就是音频设置,什么是音频设置呢?它就是需要我们选择音频设备驱动程序并优化设置.在了解音频设备之前,我们先来看看什么是音频设备. 我们的 ...

  4. Java基础学习-三元运算符和键盘录入的基本步骤和使用

    1.三元运算符的执行流程   package com.denniscui_05; /*  * 三元运算符:  *         关系表达式?表达式1:表达式2  *  * 执行流程:  *      ...

  5. qt 串口

    if(ui->connectSerialBtn->text() == tr("打开串口")) { //ui->showSerialInfo->setEnab ...

  6. Bootstrap3基础 栅格系统 col-lg/md/sm/xs-* 简单示例

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  7. python - Random常用方法记录

    import random # range [a,b) 不包含b # 获取随机整数 # randrange [a,b) 不包含b a = random.randrange(0, 101, 5) # E ...

  8. asp.net mvc 跨域配置

    修改 web.config 文件 <system.webServer> <httpProtocol> <customHeaders> <add name=&q ...

  9. acure使用

    打开,选择用IE浏览器,如果选择Chrome浏览器会提示让安装插件

  10. .class 缓存

    项目用的是Ant. 场景: Class A{ private static final String HHH="hello"; } Class B{ public void met ...