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