Codeforces 1084A - The Fair Nut and Elevator

题解链接

https://lucien.ink


题目链接

https://codeforces.com/contest/1084/problem/A


题意

  有一个电梯,它初始时会停留在第 kkk 层楼,每当有一个人要从第 aaa 楼去第 bbb 楼,电梯就会始终按照 k→a→b→kk \rightarrow a \rightarrow b \rightarrow kk→a→b→k 的路线去运行,而且电梯最多只会同时容纳一个人,现在有一个 nnn 层楼的楼房,第 iii 层有 aia_iai​ 个人,这一层的每个人每天都要按照 i→1→ii \rightarrow 1 \rightarrow ii→1→i 的顺序使用电梯,问将电梯的 kkk 设为多少时,每天的运行距离最少。


思路

  注意到 nnn 只有 100100100,暴力枚举,复杂度 O(n2)O(n ^ 2)O(n2)。


实现

https://pasteme.cn/2418

#include <bits/stdc++.h>
typedef long long ll;
ll a[1007], n, ans = 0x3f3f3f3f;
int main() {scanf("%lld", &n);for (ll i = 1; i <= n; i++) scanf("%lld", a + i);for (ll i = 1; i <= n; i++) {ll sum = 0;for (ll j = 1; j <= n; j++) sum += a[j] * 2 * (abs(i - j) + abs(j - 1) + abs(1 - i));ans = std::min(ans, sum);}printf("%lld\n", ans);return 0;
}

Codeforces 1084A - The Fair Nut and Elevator相关推荐

  1. 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 ...

  2. 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 ...

  3. CodeForces 1084A The Fair Nut and Elevator

    题意: 电梯要停在x层,每天早上要从x层去a层接人送到1层再回到x层的等待,每天晚上要从x层下到1层接人送到a层,再回到x层(对每层的乘客都是如此),电梯每走一层耗电1,问电梯停在那一层,每天的耗电最 ...

  4. Codeforces 1084A. The Fair Nut and Elevator

    枚举电梯最开始停的位置,需要注意的是底层是1层不是0层. 判断x和i的位置关系,如果x在下面,那么上班的时候需要先上去,回家的时候同理 #include<bits/stdc++.h> us ...

  5. 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 ...

  6. 【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 ...

  7. 【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 ...

  8. C - The Fair Nut and String

    C - The Fair Nut and String CodeForces - 1084C 给出一个序列,求符合规则的序列有多少个,规则有两种,一种是只含a,一种是两个a之间夹着b. 对于每一个a有 ...

  9. 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 题意: 在一棵树内找一条路径,使得从起点 ...

最新文章

  1. 硅谷产品实战-总结:15、如何组织有效的会议?
  2. OpenCV中颜色分布直方图及其应用
  3. 判断条件为空时需要注意
  4. Word2Vec ——gensim实战教程
  5. 网站运营之做到SEO操作视频教程【21讲】
  6. 一步一步学pwntools(适合新手)
  7. 助力在线教育,阿里云推出百万专项扶持基金计划
  8. ctf up怎么写 write_??零基础写网络爬虫的思路??
  9. git clone加速(github加速)
  10. 查看python下安装的包有哪些
  11. MySQL图形化管理工具
  12. oppo 手机刷机和root,还有其他必备的刷机工具,需要请进!!!
  13. CAN总线标准及协议分析
  14. matlab波浪号怎么打,数学中字母上面波浪号 波浪号怎么打到上面
  15. 卡内基梅隆 计算机音乐,卡内基梅隆大学音乐技术专业申请要求
  16. 《密码安全新技术》课程总结报告
  17. py用barh绘制水平条形图
  18. 北宋三衙的地位、待遇及其政治作用
  19. Android | HEIF图片格式显示问题
  20. 使用C语言开发web

热门文章

  1. java关闭页面6,Selenium Java关闭浏览器
  2. 【2017.01.05】装系统教程
  3. 计算机数控系统试题答案,数控技术试题库(含答案)12
  4. PTA - 数据库合集43
  5. 论文学习笔记1——《机器学习的理论局限与因果革命的7大火花》(因果推理必将带来现有人工智能领域研究的再一次巨大突破)
  6. 各家银行信用卡分期付款手续费一览表
  7. 用信用卡分期付款如何省钱
  8. Vue3图片打点自定义标记颜色形状(完整教程可直接复制项目)
  9. SQL Sever 2000中的前触发器和后触发器
  10. Spotify进军移动网络电台 Pandora坐立不安