博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 599 A. Patrick and Shopping
阅读量:5950 次
发布时间:2019-06-19

本文共 2436 字,大约阅读时间需要 8 分钟。

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.

题目大意:
有一个屋子 A 和两个超市 B 和 C,然后给定了三条道路,分别是 A--->B == d1, A---->C == d2 , B---->C == d3 的,然后让你求如何走才能
使A 到 B和C的距离最短。。
解题思路:
就是将d1 d2 d3排一下序,在跟d1 + d2 + d3比较就好了,取最小的。。。
上代码:
#include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define MM(a) memset(a,0,sizeof(a))typedef long long LL;typedef unsigned long long ULL;const int maxn = 1e3+5;const int mod = 1e9+7;const double eps = 1e-8;const int INF = 0x3f3f3f3f;LL gcd(LL a, LL b){ if(b == 0) return a; return gcd(b, a%b);}int d[3];int main(){ while(cin>>d[0]) { for(int i=1; i<3; i++) cin>>d[i]; sort(d, d+3); int sum = 0; for(int i=0; i<3; i++) sum += d[i]; if(sum >= 2*(d[0]+d[1])) sum = 2*(d[0]+d[1]); cout<
<

转载地址:http://yxpxx.baihongyu.com/

你可能感兴趣的文章
xml格式文件解析
查看>>
ios百度地图-路径规划
查看>>
Python高效编程技巧
查看>>
配置Eclipse使用maven构建项目默认JDK为1.8
查看>>
jsp内置对象以及jsp动作
查看>>
Struts上路_09-数据类型转换
查看>>
CMake与动态链接库(dll, so, dylib)
查看>>
myeclipse(eclipse)乱码处理
查看>>
SpringBoot 过滤器, 拦截器, 监听器 对比及使用场景
查看>>
数据库索引探索
查看>>
gitlab runner 优化
查看>>
快速添加百度网盘文件到Aria2 猴油脚本
查看>>
mac 无法登录mysql的解决办法
查看>>
Shiro权限判断异常之命名导致的subject.isPermitted 异常
查看>>
Hello world travels in cpp - 字符串(2)
查看>>
struts2自定义拦截器
查看>>
Eclipse安装adt插件后之后看不到andorid manger
查看>>
Kafka服务端脚本详解(1)一topics
查看>>
Zookeeper 集群安装配置,超详细,速度收藏!
查看>>
js中var self=this的解释
查看>>