Codeforces Round #332 (Div. 2) 599A Patrick and Shopping(模拟)

来源:互联网 发布:mp3编辑软件 编辑:程序博客网 时间:2024/04/30 14:07

A. Patrick and Shopping
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length d3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.

Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.

Input

The first line of the input contains three integers d1d2d3 (1 ≤ d1, d2, d3 ≤ 108) — the lengths of the paths.

  • d1 is the length of the path connecting Patrick's house and the first shop;
  • d2 is the length of the path connecting Patrick's house and the second shop;
  • d3 is the length of the path connecting both shops.
Output

Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.

Sample test(s)
input
10 20 30
output
60
input
1 1 5
output
4
Note

The first sample is shown on the picture in the problem statement. One of the optimal routes is: house  first shop  second shop house.

In the second sample one of the optimal routes is: house  first shop  house  second shop  house.



题目链接:点击打开链接

给出家与两个商店的距离以及两个商店间的距离, 现在要从家去两个商店最后回到家, 问最短路径是多少.

模拟题, 可能有四种情况, 分别是: home - shop1 - shop2 - home, home - shop1 - home - shop2 - home, 

home - shop1 - shop2 - shop1 - home, home - shop2 - shop1 - shop2 - home.

AC代码:

#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"#include "cmath"#include "utility"#include "map"#include "set"#include "vector"using namespace std;typedef long long ll;const int MOD = 1e9 + 7;ll a, b, c;int main(int argc, char const *argv[]){    scanf("%lld%lld%lld", &a, &b, &c);    printf("%lld\n", min(2 * (a + b), min(a + b + c, min(2 * (a + c), 2 * (b + c)))));    return 0;}


1 0
原创粉丝点击