Patrick and Shopping
2016-07-21 17:13
260 查看
Description
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.
![](http://7xjob4.com1.z0.glb.clouddn.com/6c7ec34dd4903f480be15eec7871994e)
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 d1, d2, d3 (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 Input
Input
Output
Input
Output
Hint
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house
![](http://7xjob4.com1.z0.glb.clouddn.com/7dba3e435f3fa0126d9a286022c47850)
first
shop
![](http://7xjob4.com1.z0.glb.clouddn.com/7dba3e435f3fa0126d9a286022c47850)
second shop
![](http://7xjob4.com1.z0.glb.clouddn.com/7dba3e435f3fa0126d9a286022c47850)
house.
In the second sample one of the optimal routes is: house
![](http://7xjob4.com1.z0.glb.clouddn.com/7dba3e435f3fa0126d9a286022c47850)
first shop
![](http://7xjob4.com1.z0.glb.clouddn.com/7dba3e435f3fa0126d9a286022c47850)
house
![](http://7xjob4.com1.z0.glb.clouddn.com/7dba3e435f3fa0126d9a286022c47850)
second
shop
![](http://7xjob4.com1.z0.glb.clouddn.com/7dba3e435f3fa0126d9a286022c47850)
house.#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
long long a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
if(a>b)
{
long long tmp;
tmp=a;
a=b;
b=tmp;
}
long long dis1=2*(a+b),dis2=a+b+c,dis3=2*(a+c);
printf("%lld\n",min(min(dis1,dis2),dis3));
return 0;
}
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 d1, d2, d3 (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 Input
Input
10 20 30
Output
60
Input
1 1 5
Output
4
Hint
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.#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
long long a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
if(a>b)
{
long long tmp;
tmp=a;
a=b;
b=tmp;
}
long long dis1=2*(a+b),dis2=a+b+c,dis3=2*(a+c);
printf("%lld\n",min(min(dis1,dis2),dis3));
return 0;
}
相关文章推荐
- 安卓入门之安卓系统架构
- tomcat启动startup.bat一闪而过
- Linux下java环境及tomcat部署
- linux 用户和组管理
- 小记——linux定时器之alarm
- Centos6.5使用yum安装mysql——快速上手必备
- Linux常用命令大全
- shell脚本学习笔记
- jira的安装部署
- Options for mounting NFS filesystem
- CentOS 6 时间,时区,设置修改及时间同步
- 关于disconf linux下报cannot get host info的问题
- linux下使用yum安装svn
- Log4j 日志文件Linux/Mac/Windows通用存放位置设置
- linux c下简单实现服务端与多客户端同时连接
- 构建属于自己的elasticsearch Docker镜像
- tomcat 修改默认字符集
- [置顶] Linux下WebLogic建域
- Patrick and Shopping(距离比较)
- exynos4412开发板设备注册与驱动注册剖析