好不容易找到的。

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double a,b,c,x,y,z,ans,l,w,h;
double f(double x)
{
return (double(x*x));
} double min(double x,double y)
{
if(x>y) return y;
else return x;
} void count1()
{
ans=sqrt(double(f(a-x)+f(b-y)+f(c-z)));
} void count2()
{
double ans1,ans2;
if(b==||b==w)
{
ans1=sqrt(double(min(f(h-z+w+h-c),f(z+w+c))+f(x-a)));
ans2=sqrt(double(min(f(l-x+w+l-a),f(x+w+a))+f(c-z)));
}
else if(a==||a==l)
{
ans1=sqrt(double(min(f(w-y+l+w-b),f(y+l+b))+f(c-z)));
ans2=sqrt(double(min(f(h-z+l+h-c),f(z+l+c))+f(b-y)));
}
else
{
ans1=sqrt(double(min(f(w-y+h+w-b),f(y+h+b))+f(x-a)));
ans2=sqrt(double(min(f(l-x+h+l-a),f(x+h+a))+f(b-y)));
}
ans=min(ans1,ans2);
} void count3()
{
if(a==||a==l)
{
if(y==||y==w)
ans=sqrt(double(f(labs(x-a)+labs(b-y))+f(c-z)));
else
ans=sqrt(double(f(labs(z-c)+labs(x-a))+f(b-y)));
}
else if(b==||b==w)
{
if(x==||x==l)
ans=sqrt(double(f(labs(x-a)+labs(b-y))+f(c-z)));
else
ans=sqrt(double(f(labs(c-z)+labs(b-y))+f(a-x)));
}
else
{
if(x==||x==l)
ans=sqrt(double(f(labs(c-z)+labs(x-a))+f(b-y)));
else
ans=sqrt(double(f(labs(c-z)+labs(b-y))+f(a-x)));
}
} int main()
{
cin>>l>>w>>h;
cin>>a>>b>>c>>x>>y>>z;
if((a==x&&(a==||a==l))||(b==y&&(b==||b==w))||(c==z&&(c==||c==h)))
count1();
else if((a==&&x==l)||(b==&&y==w)||(c==&&z==h)||(a==l&&x==)||(b==w&&y==)||(c==h&&z==))
count2();
else
count3();
cout<<setiosflags(ios::fixed)<<setprecision()<<ans<<endl;
return ;
}

【算法】shortest distance的更多相关文章

  1. PAT Advanced 1046 Shortest Distance (20 分) (知识点:贪心算法)

    The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...

  2. PAT——甲级1046S:shortest Distance

    这道题,折磨了我一个多小时,前前后后写了三个算法. 1046 Shortest Distance (20 point(s)) The task is really simple: given N ex ...

  3. A1046 Shortest Distance (20)(20 分)

    1046 Shortest Distance (20)(20 分)提问 The task is really simple: given N exits on a highway which form ...

  4. 【LeetCode】1182. Shortest Distance to Target Color 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+二分查找 日期 题目地址:https://lee ...

  5. [CareerCup] 18.5 Shortest Distance between Two Words 两单词间的最短距离

    18.5 You have a large text file containing words. Given any two words, find the shortest distance (i ...

  6. [Locked] Shortest Distance from All Buildings

    Shortest Distance from All Buildings You want to build a house on an empty land which reaches all bu ...

  7. maximum shortest distance

    maximum shortest distance Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...

  8. PAT1046: Shortest Distance

    1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...

  9. [Swift]LeetCode821. 字符的最短距离 | Shortest Distance to a Character

    Given a string S and a character C, return an array of integers representing the shortest distance f ...

  10. LeetCode 613. Shortest Distance in a Line

    Table point holds the x coordinate of some points on x-axis in a plane, which are all integers. Writ ...

随机推荐

  1. mysql id从n 开始

    mysql 全部删除数据后设置 id从1开始: truncate table table_name mysql  删除部分数据后设置 id从n开始 ALTER TABLE user auto_incr ...

  2. 【Android Studio安装部署系列】六、在模拟器上运行项目

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 在模拟器上运行项目的步骤.不过在实际开发中,一般不采用这种方式,因为影响电脑的运行,所以一般使用真机运行项目. 运行项目 创建模拟器 ...

  3. 旅游公司租车问题 —— 动态规划 v.s. + Leapms线性规划

    有一个旅游公司承包一条旅游线路,未来四周内的大巴车需求分别是:4辆.1辆.4辆和5辆.该公司向租车公司租赁服务,租车公司的计价方案是:租车收取一次性手续费3000,每车每周费用2000.求最节省租车方 ...

  4. 如何在linux下使用git管理上传代码&误删文件修复

    首先需要安装git,sudo apt-get install git,这时就可以下载代码了. 然后先在gituhub上新建一个仓库,然后先在本地建一个git目录,git init 然后再配置用户名和邮 ...

  5. 浅析HttpSession

    苏格拉底曰:我唯一知道的,就是自己一无所知 源头 最近在翻阅Springboot Security板块中的会话管理器过滤器SessionManagementFilter源码的时候,发现其会对单用户的多 ...

  6. 云计算OpenStack:云计算介绍及组件安装(一)--技术流ken

    云计算介绍 当用户能够通过互联网方便的获取到计算.存储等服务时,我们比喻自己使用到了“云计算”,云计算并不能被称为是一种计算技术,而更像是一种服务模式.每个运维人员心里都有一个对云计算的理解,而最普遍 ...

  7. [转]How to Download and Setup Blue Prism

    本文转自:https://www.hopetutors.com/blog/uncategorized/how-to-download-and-setup-blue-prism/ The Downloa ...

  8. 详解RPC远程调用和消息队列MQ的区别

    PC(Remote Procedure Call)远程过程调用,主要解决远程通信间的问题,不需要了解底层网络的通信机制. RPC框架 知名度较高的有Thrift(FB的).dubbo(阿里的). RP ...

  9. jQuery元素操作

    jQuery中创建元素及追加元素 DOM中可以动态创建元素:document.createElement(“标签的名字”); jQuery中同样可以创建元素标签,并且返回的就是jQuery对象,可以直 ...

  10. asp.net core 自定义认证方式--请求头认证

    asp.net core 自定义认证方式--请求头认证 Intro 最近开始真正的实践了一些网关的东西,最近写几篇文章分享一下我的实践以及遇到的问题. 本文主要介绍网关后面的服务如何进行认证. 解决思 ...