↓ 跳过正文
  1. Posts/

codeforces #332 div 2 A. Patrick and Shopping

·646 字·2 分钟
 1#include <cstdio>
 2#include <iostream>
 3#include <cmath>
 4using namespace std;
 5long long d1,d2,d3;
 6int main()
 7{
 8cin>>d1>>d2>>d3;
 9long long ans = 999999999999;
10ans = min(ans,d1+d2+d3);
11ans = min (ans,d1*2+d2*2);
12ans = min (ans,d1*2+2*d3);
13ans = min(ans,d2*2+2*d3);
14cout<<ans<<endl;
15return 0;
16}

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 _d_1 meter long road between his house and the first shop and a _d_2 meter long road between his house and the second shop. Also, there is a road of length _d_3 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 的家与两个商店之间的道路示意图

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 _d_1, _d_2, _d_3 (1 ≤ _d_1, _d_2, _d_3 ≤ 108) – the lengths of the paths.

  • _d_1 is the length of the path connecting Patrick’s house and the first shop;
  • _d_2 is the length of the path connecting Patrick’s house and the second shop;
  • _d_3 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.

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 _d_1 meter long road between his house and the first shop and a _d_2 meter long road between his house and the second shop. Also, there is a road of length _d_3 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 的家与两个商店之间的道路示意图

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 _d_1, _d_2, _d_3 (1 ≤ _d_1, _d_2, _d_3 ≤ 108) – the lengths of the paths.

  • _d_1 is the length of the path connecting Patrick’s house and the first shop;
  • _d_2 is the length of the path connecting Patrick’s house and the second shop;
  • _d_3 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.

水题。

相关文章

codeforces 589 B - Layer Cake

·698 字·2 分钟
B - Layer Cake **Time Limit:**6000MS **Memory Limit:**524288KB 64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 589B Description Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n rectangular cake layers. The length and the width of the i-th cake layer were a__i and b__i respectively, while the height of each cake layer was equal to one.

codeforces #324 div 2 A. Olesya and Rodion

·377 字·1 分钟
A. Olesya and Rodion time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them.

[转自codeforces] How to come up with the solutions: techniques

·901 字·2 分钟
As I work with students I often face the situation when if a problem doesn’t seem clear to a student at the first sight, it makes them unable to solve it. Indeed, you always hear about specific methods and techniques. But you don’t hear about how to think in order to apply them. In this note I’ll try to sum up my experience of solving programming contest problems. However, some pieces of advice will also be applicable for olympiads in mathematics and your first steps in academic research.