Codeforces A. Trip For Meal
1 second
512 megabytes
standard input
standard output
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's and Eeyore's house is b meters, between Owl's and Eeyore's house is cmeters.
For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal n times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).
Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.
First line contains an integer n (1 ≤ n ≤ 100) — number of visits.
Second line contains an integer a (1 ≤ a ≤ 100) — distance between Rabbit's and Owl's houses.
Third line contains an integer b (1 ≤ b ≤ 100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer c (1 ≤ c ≤ 100) — distance between Owl's and Eeyore's houses.
Output one number — minimum distance in meters Winnie must go through to have a meal n times.
3
2
3
1
3
1
2
3
5
0
In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.
每次走最短的距离就行了;
代码写的有点长;
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std; int n,d,b,c,a[][],ans; int main(){
scanf("%d",&n);
n--;
scanf("%d%d%d",&d,&b,&c);
a[][]=d;
a[][]=b;
a[][]=d;
a[][]=c;
a[][]=b;
a[][]=c;
int u=;
for(int i=;i<=n;i++){
if(u==){
if(a[u][]<a[u][]){
ans+=a[u][];
u=;
continue;
}else{
ans+=a[u][];
u=;
continue;
}
}
if(u==){
if(a[u][]<a[u][]){
ans+=a[u][];
u=;
continue;
}else{
ans+=a[u][];
u=;
continue;
}
}
if(u==){
if(a[u][]<a[u][]){
ans+=a[u][];
u=;
continue;
}else{
ans+=a[u][];
u=;
continue;
}
}
}
printf("%d",ans);
}
Codeforces A. Trip For Meal的更多相关文章
- codeforces Round #441 A Trip For Meal【思路/模拟】
A. Trip For Meal time limit per test 1 second memory limit per test 512 megabytes input standard inp ...
- CF876A Trip For Meal
CF876A Trip For Meal 题意翻译 小熊维尼非常喜欢蜂蜜! 所以他决定去拜访他的朋友. 小熊有三个最好的朋友:兔子,猫头鹰和小毛驴,每个人都住在自己的房子里. 每对房屋之间都有蜿蜒的小 ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal
http://codeforces.com/contest/876/problem/A 题意: 一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就 ...
- [Codeforces 1037E] Trip
[题目链接] http://codeforces.com/problemset/problem/1037/E [算法] 首先离线 , 将问题倒过来考虑 , 转化为 : 每次删除一条边 , 此时最多有多 ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
A. Trip For Meal 题目链接:http://codeforces.com/contest/876/problem/A 题目意思:现在三个点1,2,3,1-2的路程是a,1-3的路程是b, ...
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #441 (Div. 2)
Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...
- Codeforces#441 Div.2 四小题
Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...
- ACM-ICPC (10/16) Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
A. Trip For Meal Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. ...
随机推荐
- 团队作业8——Beta 阶段冲刺3rd day
一.当天站立式会议 二.每个人的工作 (1)昨天已完成的工作(具体在表格中) 添加了订单功能,并且对订单功能进行了测试 (2)今天计划完成的工作(具体如下) 添加支付功能 (3) 工作中遇到的困难(在 ...
- 团队作业4——第一次项目冲刺(Alpha版本)第五天
天气阴转晴 一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 1.界面 功能界面已经大致完成 实现判断学生答题正误的界面 2.出题方面 实现错题库的构造 四.困难与问题 1.项 ...
- 201521123119《Java程序设计》第5周学习总结
1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 2. 书面作业 代码阅读:Child压缩包内源代码 Q1.1 com.parent包中Child.java文件能否编译通过?哪 ...
- 201521145048《Java程序设计》第4周学习总结
1. 本章学习总结 学会了如何去设计一个类,尽量用private修饰属性,public修饰方法. 了解继承的目的. 了解继承和多态的关系. 了解关键字extends super final overr ...
- 201521123035《Java程序设计》第二周学习总结
1.本周学习总结 这周学习了各种类与对象,还有基本类型的打包器,最主要的是字符串对象,老师还特地花了一节课时间讲解代码与习题. 2.书面作业 1.使用Eclipse关联jdk源代码,并查看String ...
- 201521123026 《Java程序设计》第一周学习总结
1. 本章学习总结 1.简要了解JAVA的发展史以及其特点(面向对象.跨平台性,健壮性,安全性,可移植性,多线程性,动态性等) 2.认识JAVA三大平台(Java SE,Java EE,JavaME) ...
- 201521123097《Java程序设计》第九周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己 ...
- 2015211230108《Java程序设计》第10周学习总结
1. 本周学习总结 2. 书面作业 Q1.finally 题目4-2 1.1 截图你的提交结果(出现学号) 1.2 4-2中finally中捕获异常需要注意什么? finally的作用: 1.确定程序 ...
- Spring详解(六)------AOP 注解
上一篇博客我们讲解了 AspectJ 框架如何实现 AOP,然后具体的实现方式我们是通过 xml 来进行配置的.xml 方式思路清晰,便于理解,但是书写过于麻烦.这篇博客我们将用 注解 的方式来进行 ...
- yum仓库管理
yum在线管理 rpm包的管理分为 rpm命令管理和yum在线管理,rpm命令管理由于可能需要解决各种依赖问题,在安装软件的时候可能显得比较麻烦,然而,yum在线管理正好和它相反.Yum(全称为 Ye ...