首页 > 其他分享 >Codeforces876A-Trip For Meal

Codeforces876A-Trip For Meal

时间:2022-11-22 19:33:07浏览次数:35  
标签:begin end house Codeforces876A Meal Rabbit between now Trip


A. Trip For Meal


time limit per test


memory limit per test


input


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

Winnie-the-Pooh does not like physical activity. He wants to have a meal n

Input


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


Output one number — minimum distance in meters Winnie must go through to have a meal n

Examples


input


3 2 3 1


output


3


input


1 2 3 5


output


0

Note


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.

题解:Div2T1应该比较简单,直接模拟就可以了。

Code:

var n,a,b,c,now,i,x,ans,p:longint;
begin
readln(n);
readln(a);
readln(b);
readln(c);
now:=1;
for i:=2 to n do
begin
if now=1 then
begin
if a<b then begin x:=a;p:=2;end
else begin x:=b;p:=3;end;
end;
if now=2 then
begin
if a<c then begin x:=a;p:=1;end
else begin x:=c;p:=3;end;
end;
if now=3 then
begin
if b<c then begin x:=b;p:=1;end
else begin x:=c;p:=2;end;
end;
ans:=ans+x;
now:=p;
end;
writeln(ans);
end.

标签:begin,end,house,Codeforces876A,Meal,Rabbit,between,now,Trip
From: https://blog.51cto.com/u_15888102/5878386

相关文章

  • GL-Planning a trip 20221103 same
    Planningatrip20221103Needtogetawayfromitall?Planyourdreamvacationwithyourclassmates,Whowouldyouliketogoonholidaywith?这节课有人吗?I......
  • GL-Planning a trip 20221103
    Planningatrip这节课有人吗?Idon'thaveajobatpresentIhavebeenworkingfor5yearsmyhobbiesareplayvideogamesandlong-diatancerunning.Youwina......
  • Planar Mapping, Triplanar Mapping
    写在前面:本文章为个人学习笔记,方便以后自己复习,也希望能帮助到他人。由于本人水平有限难免出现错误,还请评论区指出,多多指教。部分图元和素材来源于网络,如有侵权请联系本......
  • Ntrip介绍
    @目录简介什么是CORS什么是Ntrip什么是RTK挂载点Ntrip系统的组成NtripClient获取源列表差分GPS获取差分数据流程简介简单介绍下Ntrip什么是CORSCORS(Continuously Oper......
  • react实战笔记79:加载meals数据2
     通过父子传值处理......
  • c#的winform组件中,Menu和MenuStrip,以及MenuItem和ToolStripMenuItem有什么区别?
    https://zhidao.baidu.com/question/572383135.html首先从字面上理解,Menu就是菜单,MenuStrip是菜单栏,MenuItem是菜单项,ToolStripMenuItem是工具栏菜单项Menu是Form类的一个......
  • CF1250C Trip to Saint Petersburg
    题目传送门思路线段树入门题。不妨固定一个右端点\(r\),把所有右端点小于\(r\)的区间都在\(1\)至此区间的左端点处update一个\(p\),然后每次都给区间\(1\)至\(......
  • VS控件-Toolstrip
    1.工具栏TooIStrip概述Windows窗体中的工具栏控件用于显示一系列菜单选项的位图按钮。这样单击工具栏中的一个按钮,就相当于选择了一个菜单项。工具栏上的按钮通常包含......
  • Almost Triple Deletions(CF1699D)
    AlmostTripleDeletions(CF1699D)考虑DP。设$dp_i$为强制保留这一个数,最多可以剩下几个数。发现:当一个区间$[l,r]$满足$len\equiv0(mod\2)\land区......
  • CF605E Intergalaxy Trips
    linkSolution不是很难,不知道为啥之前没做出来。不难看出我们有如下转移式:\[f_{u}=\sumf_{v}\timesP_{u,v}\times(\prod_{f_t<f_v}(1-P_{u,t}))+1\]那么我们可以发......