CodeForces - 1084A The Fair Nut and Elevator 数学
题目
The Fair Nut lives in n story house. ai people live on the i-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 x-th floor, but x hasn’t been chosen yet. When a person needs to get from floor a to floor b, elevator follows the simple algorithm:
Moves from the x-th floor (initially it stays on the x-th floor) to the a-th and takes the passenger.
Moves from the a-th floor to the b-th floor and lets out the passenger (if a equals b, elevator just opens and closes the doors, but still comes to the floor from the x-th floor).
Moves from the b-th floor back to the x-th.
The elevator never transposes more than one person and always goes back to the floor x before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the a-th floor to the b-th floor requires |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 x-th floor. Don’t forget than elevator initially stays on the x-th floor.
题意:
找一个最省电的电梯停留楼层。已知楼高和每层楼有多少人,每个人每天用电梯2次
题解:
模拟实际,耗电量=电梯去接人+电梯送到目的地+电梯回停留楼层
让电梯分别停留在1-n层,计算每次的耗电量用d数组保存,最后找出数组中的最小值即可
代码
#include<iostream>
#include<cmath>
using namespace std;
int d[107]; //x设在每层楼所用的电
int main()
{int n;cin>>n; //n层楼int a[107]; //每层多少人for(int i=1;i<=n;i++) cin>>a[i];for(int j=1;j<=n;j++) //j为每次设定的x{int sum=0;for(int i=1;i<=n;i++) //每层楼要耗得电数{sum+=(abs(j-i)+abs(i-1)+abs(j-1))*2*a[i];}d[j]=sum;}int t=100000000;for(int i=1;i<=n;i++){if(d[i]<t)t=d[i];}cout<<t<<endl;return 0;
}
感谢观看!
CodeForces - 1084A The Fair Nut and Elevator 数学相关推荐
- Codeforces 1084A - The Fair Nut and Elevator
Codeforces 1084A - The Fair Nut and Elevator 题解链接 https://lucien.ink 题目链接 https://codeforces.com/con ...
- CodeForces 1084A The Fair Nut and Elevator 题解
A. The Fair Nut and Elevator time limit per test : 1 second memory limit per test : 256 megabytes in ...
- CodeForces 1084A The Fair Nut and Elevator
题意: 电梯要停在x层,每天早上要从x层去a层接人送到1层再回到x层的等待,每天晚上要从x层下到1层接人送到a层,再回到x层(对每层的乘客都是如此),电梯每走一层耗电1,问电梯停在那一层,每天的耗电最 ...
- Codeforces 1084A. The Fair Nut and Elevator
枚举电梯最开始停的位置,需要注意的是底层是1层不是0层. 判断x和i的位置关系,如果x在下面,那么上班的时候需要先上去,回家的时候同理 #include<bits/stdc++.h> us ...
- CodeForces 1084D The Fair Nut and the Best Path(树形dp)
题目描述 The Fair Nut is going to travel to the Tree Country, in which there are n cities. Most of the l ...
- 【CodeForces - 1084D】The Fair Nut and the Best Path (树形dp)
题干: The Fair Nut is going to travel to the Tree Country, in which there are nn cities. Most of the l ...
- 【CodeForces - 1084C】The Fair Nut and String(思维,组合数学)
题干: The Fair Nut found a string ss. The string consists of lowercase Latin letters. The Nut is a cur ...
- C - The Fair Nut and String
C - The Fair Nut and String CodeForces - 1084C 给出一个序列,求符合规则的序列有多少个,规则有两种,一种是只含a,一种是两个a之间夹着b. 对于每一个a有 ...
- CF 1083 A. The Fair Nut and the Best Path
A. The Fair Nut and the Best Path https://codeforces.com/contest/1083/problem/A 题意: 在一棵树内找一条路径,使得从起点 ...
最新文章
- java运算符-逻辑、三元运算符
- pandas.DataFrame.to_dict()的使用详解
- 网站优化离不开内容更新
- 关于软件版本命名的方法
- 【首创】完美解决scrollview与menu的兼容问题
- maple 2018 窗口关闭提示乱码_iPhone最废柴却无法关闭的俩功能,我终于屏蔽了!...
- 计算机系十周年聚会邀请函,毕业十周年同学聚会邀请函
- 基于JAVA+SpringBoot+Mybatis+MYSQL的小区物业管理系统
- Python Tricks —— 计算 1+1/2+1/4+...=2
- 省市区三级联动插件(v-distpicker)
- php繁体转为简体的函数,繁体中文转换为简体中文的PHP函数
- 2020产品经理升职攻略-直播分享课
- 6.2.2 分区与副本
- 漂亮实用的jQuery倒计时插件特效代码
- OpenCV——透视变换
- 铝电解电容和钽电容区别
- Python爬虫方法三部曲之二-实战训练
- 本周聚划算| 避免上班5分钟被开除 直降2000元企业办公实用利器一站全掌握
- STM32学习笔记(六)丨TIM定时器及其应用(输入捕获丨测量PWM波形的频率和占空比)
- SCADA软件平台数据库功能的应用