CodeForces 1084A The Fair Nut and Elevator
题意:
电梯要停在x层,每天早上要从x层去a层接人送到1层再回到x层的等待,每天晚上要从x层下到1层接人送到a层,再回到x层(对每层的乘客都是如此),电梯每走一层耗电1,问电梯停在那一层,每天的耗电最少。(电梯每次运载1人)
思路:
此题不难,就是读题太费劲,数据量不大,暴力去找每一层即可,对于a层的乘客,每天的耗电为:
a[i] * (fabs(i - index) + i + index - 2) * 2
Code:
#include <iostream>
#include <cmath>#define INF 0x3f3f3f3f
#define max(x, y) (x >= y ? x : y)
#define min(x, y) (x < y ? x : y)using namespace std;const int maxn = 105;int a[maxn];
int n;int solve(int index)
{int sum = 0;for (int i = 1; i <= n; i++){sum += a[i] * (fabs(i - index) + i + index - 2) * 2;}return sum;
}int main()
{cin >> n;for (int i = 1; i <= n; i++) cin >> a[i];int ans = INF;for (int i = 1; i <= n; i++){int val = solve(i);ans = min(ans, val);}cout << ans << 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 数学
题目 The Fair Nut lives in n story house. ai people live on the i-th floor of the house. Every person ...
- 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 题意: 在一棵树内找一条路径,使得从起点 ...
最新文章
- python3读取excel数据-python3读取Excel表格数据的代码分享
- c语言入门中冒泡排序的例题,选择排序和冒泡排序例题解析(c语言)
- oracle数据结构是什么意思,Oracle数据结构知多少(一)
- 2021 年云原生技术发展现状及未来趋势
- lisp提取长方形坐标_用 Python 对图片主体轮廓进行提取、颜色标记、并计算区域面积...
- cuSPARSE库:(十四)求解稀疏三角形线性系统(solution of sparse triangular linear systems)
- 百度大脑 EasyDL 专业版最新上线自研超大规模视觉预训练模型
- cPanel附加域名出现Error from park wrapper: 使用带以下 IP 的命名服务器:
- python有哪些用途-python是什么?python的用途
- CentOS 安装快速Nginx-1.12.0
- 计算机毕业设计Java宠物医院管理系统(源码+系统+mysql数据库+lw文档)
- 关于Linux系统之VM安装配置(每一个步骤都超级详细的哦!)
- 推荐3款手机远程控制电脑的软件 专业 好用 免费
- 不小心隐藏IDEA的main menu,让它恢复显示的解决方法
- 《A Tale of Two Worlds (CCS‘19)》笔记
- 手机应用误删怎么恢复
- java海贼王秘宝传说下载_海贼王秘宝传说攻略 星月岛任务详解一览
- 优盘扩容修复 u盘工具
- thinkphp Malformed UTF-8 characters, possibly incorrectly encoded报错解决方案
- i908的串口连接中断的解决[转]
热门文章
- MT6169+MT6158设计资料参考指南
- java,javase,javaee区别
- 【论文翻译】R-CNN
- 将搜狗浏览器收藏夹导入到IE、Firefox、Chrome
- Maven学习(十四)profile标签
- 关于mysql的中文乱码全解 java方式
- OKapi BM25 算法
- pts/0 pts/1
- element table 拖动改变列宽
- (已解决)BadValue (integer parameter out of range for operation) opcode of failed request: 152 (GLX)