http://codeforces.com/contest/876/problem/A

题意:

一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就继续去另外的朋友家。

当他在一个朋友家吃的时候,另外的朋友家的蜂蜜就会恢复供应。

问这个人走的最小的距离。

一开始因为审题不清楚,忽略了第一次是固定的,所以wa了。

代码:

 #include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
int n; scanf("%d",&n); n--; int a[]; for (int i = ;i < ;i++) scanf("%d",&a[i]); if (n == )
{
printf("0\n"); return ;
} int ans = ; if (a[] < a[]) ans += a[];
else ans += a[]; n--; sort(a,a+); ans += n * a[]; printf("%d\n",ans); return ;
}

最新文章

  1. Mongodb学习笔记三(Mongodb索引操作及性能测试)
  2. 【python】函数
  3. 磁盘、分区及Linux文件系统 [Disk, Partition, Linux File System]
  4. pycharm基本设置
  5. LeetCode Binary Tree Right Side View (DFS/BFS)
  6. STL 案例分析
  7. oracle--insert
  8. iOS开发——面试笔试精华(四)
  9. 如何安装SQL Server 2008数据库(带完整图解)
  10. JavaEE中遗漏的10个最重要的安全控制
  11. My.Ioc 代码示例——实现自动注册/解析
  12. PHP7.27: Cookie and Session
  13. 2016年 CodePen 最热门的前端代码 Top 100
  14. 解决ubuntu开机进入grub界面的问题
  15. centos 下安装redis
  16. Echarts的使用方法
  17. Turn your Session into FlushMode.COMMIT/AUTO or remove &#39;readOnly&#39; marker from transaction 异常一例
  18. 详细注释!二维码条码扫描源码,使用Zxing core2.3
  19. webview中事件的用法
  20. PostgreSQL基础命令

热门文章

  1. windows下安装mysql以及启动
  2. 【吐槽向】iOS 中的仿射变换
  3. 使用CoreRT将.NET Core发布为Native应用程序
  4. python学习03-数据类型
  5. AngularJs的resource服务与Rest服务交互
  6. python 对模块的应用你还得练点这些
  7. spring Boot+spring Cloud实现微服务详细教程第二篇
  8. 笔记:Struts2 输入校验
  9. linux 的tee命令
  10. 使用selenium时提示:ImportError:No module named selenium