【算法】shortest distance
好不容易找到的。
#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的更多相关文章
- 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 ...
- PAT——甲级1046S:shortest Distance
这道题,折磨了我一个多小时,前前后后写了三个算法. 1046 Shortest Distance (20 point(s)) The task is really simple: given N ex ...
- A1046 Shortest Distance (20)(20 分)
1046 Shortest Distance (20)(20 分)提问 The task is really simple: given N exits on a highway which form ...
- 【LeetCode】1182. Shortest Distance to Target Color 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+二分查找 日期 题目地址:https://lee ...
- [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 ...
- [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 ...
- maximum shortest distance
maximum shortest distance Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- PAT1046: Shortest Distance
1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- [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 ...
- 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 ...
随机推荐
- 基于Cisco packet tracer的AAA认证
---恢复内容开始--- 1.Topology Diagram拓扑图 2.配置ip地址 3.路由互通 pc1--pc2 pc1--pc3 pc2--pc3 4.指令文件 R1: R1(config)# ...
- win10激活(免费+永久)视频教程
U盘重装Win10系统视频教程 好久不见,不知同学们有没有想我~ 最近因为工作太忙所以好久都没有写文章了,很多朋友希望我推一期win10激活教程,所以今天带三胖打完针后,开始写一期win10激活教程: ...
- Prometheus安装和配置node_exporter监控主机
Node_exporter是可以在* Nix和Linux系统上运行的计算机度量标准的导出器. Node_exporter 主要用于暴露 metrics 给 Prometheus,其中 metrics ...
- .NET Core微服务之基于Ocelot实现API网关服务(续)
Tip: 此篇已加入.NET Core微服务基础系列文章索引 一.负载均衡与请求缓存 1.1 负载均衡 为了验证负载均衡,这里我们配置了两个Consul Client节点,其中ClientServic ...
- RomUtil【Android判断手机ROM,用于判断手机机型】
参考资料 Android判断手机ROM 正文 有时候需要判断手机系统的ROM,检测ROM是MIUI.EMUI还是Flyme,可以使用getprop命令,去系统build.prop文件查找是否有对应属性 ...
- 90后的青春,定格在被淡忘的QQ空间里
QQ空间,这个曾经陪我们从童年到少年再到成年,从2G时代再到如今的4G末,占据了我们太多的青春回忆,如今好友空间动态更新的不在像从前那样频繁.依稀记得当年的好友买卖,抢车位再或者情侣空间,现在想想那时 ...
- springboot~@Query到DTO对象
我们有时在进行开发过程中,使用jpa的@Query注解去选择多张表然后返回一个DTO对象,这个时候我们需要特殊处理一下,因为默认情况下,你的jpa代码是不认DTO对象的. 参考文章:https://s ...
- mybatis自动填充时间字段
对于实体中的created_on和updated_on来说,它没有必要被开发人员去干预,因为它已经足够说明使用场景了,即在插入数据和更新数据时,记录当前时间,这对于mybatis来说,通过拦截器是可以 ...
- 深入解读MySQL8.0 新特性 :Crash Safe DDL
前言 在MySQL8.0之前的版本中,由于架构的原因,mysql在server层使用统一的frm文件来存储表元数据信息,这个信息能够被不同的存储引擎识别.而实际上innodb本身也存储有元数据信息.这 ...
- 浅谈基于Intellij IDEA Maven的配置与使用
在java开发中,引入jar包的方式从种类上划分,可分为自动导入和手动导入,然而,手动导入繁琐,不是很适合当前开发模式,手动导入也被自动导入所取代. 当前,Maven和Gradle是比较主流的自动导入 ...