【算法】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 ...
随机推荐
- AI - 深度学习之美十四章-概念摘要(1~7)
原文链接:https://yq.aliyun.com/topic/111 本文是对原文内容中部分概念的摘取记录,可能有轻微改动,但不影响原文表达. 01 - 一入侯门"深"似海,深 ...
- 从壹开始微服务 [ DDD ] 之五 ║聚合:实体与值对象 (上)
前言 哈喽,老张是周四放松又开始了,这些天的工作真的是繁重,三个项目同时启动,没办法,只能在深夜写文章了,现在时间的周四凌晨,白天上班已经没有时间开始写文章了,希望看到文章的小伙伴,能给个辛苦赞
- mysql的学习笔记(九)
mysql不支持FULL JOIN时可用UNION ALL代替 SELECT t1.user_id,t2.user_name FROM t1 LIFT JOIN t2 ON t1.user_id = ...
- NavUtils【底部虚拟导航栏工具类】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 获取底部虚拟导航栏的高度值 效果图 代码分析 checkDeviceHasNavigationBar(Context context ...
- Chapter 5 Blood Type——32
"Where are you all going, exactly?" He was still looking ahead, expressionless. “真的,你要去哪里? ...
- jenkins maven 自动远程发布到服务器,钉钉提醒团队
jenkins 自动远程发布到服务器 1.安装jenkins 安装过程:自行百度 英文不好的,不要装最新版的jenkins.建议安装Jenkins ver. 2.138.4,此版本可以设置中文语言,设 ...
- DS控件库 DSLed控件呈现滚动字幕效果
滚动字幕效果在DSled上可以使用偏移来实现,代码如下 运行效果
- 使用visualStudio2017创建一个简单的控制台程序
步骤: 1. 打开visual studio开发工具 2. 选择文件>新建>项目 如下图所示: 3. 选择window金典桌面>控制台应用程序 并填写好想项目名称和选择项目存储地址 ...
- PHP正则表达式二分法实现mysql盲注脚本
$sUrl = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $sPost = 'inject=Inject&injection='; $sCharset = 'AB ...
- 突破瓶颈,再出发 - PM过程能力成熟度5级
尽管程度不同,但PM的每个级别都在践行过程改进,并在4级借助数据,达到了“登峰造极”的程度.随着量化与统计分析的深入,项目会被优化到极其稳定的状态,组织的过程改进也就此进入了平台期. 平台期可以被视为 ...