【算法】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 ...
随机推荐
- Spring Cloud Eureka 你还在让它裸奔吗??
前些天栈长在微信公众号Java技术栈分享了 Spring Cloud Eureka 最新版 实现注册中心的实战教程:Spring Cloud Eureka 注册中心集群搭建,Greenwich 最新版 ...
- python的append insert extend pop del remove使用
对于 python 数组的操作,有插入和删除,下面介绍各个函数的功能: 插入 插入的函数有 append.insert .extend append append(i) 是在数组的末尾插入一个元素 i ...
- LindDotNetCore~添加路由前缀
回到目录 路由前缀就是我们所说的api/values里的api,这里的api可以用其它具体含义的字符表示,如Shop,Order,Game,它可以表示一个个模块,这一般在单体架构里;也可以是一个个小服 ...
- 全文检索-Elasticsearch (四) elasticsearch.net 客户端
本篇摘自elasticsearch.net search入门使用指南中文版(翻译) 原文:http://edu.dmeiyang.com/book/nestusing.html elasticsear ...
- 微信小程序开发07-列表页面怎么做
接上文:微信小程序开发06-一个业务页面的完成 github地址:https://github.com/yexiaochai/wxdemo 我们首页功能基本完成,我对比了下实际工作中的需求,完成度有7 ...
- .NET移动开发,关于发布IOS的方法(本人亲身经历折腾很久终于成功)
前情提要:这位.NET程序员兄弟使用Smobiler开发了一个APP,尽管Smobiler云平台已经最大限度的简化了iOS应用的打包操作,但仍绕不开苹果公司强制要求的p12文件,p12文件需要开发者自 ...
- composer windows下安装
composer windows安装 因要使用PhpSpreadsheet处理excel表格 选择composer安装 1. 下载Composer-Setup.exe 2.点击直接运行---选择ph ...
- 微信小程序 canvas 文字自动换行
Page({ drawCanvas: function(ctx) {// 地址 ctx.setFontSize() ctx.setFillStyle('#9E7240') ctx.textAlign= ...
- 第十课html5 新增标签及属性 html5学习5
一.常用新增标签 1.header:定义页面的页眉头部 2.nav:定义导航栏 3.footer:定义页面底部,页脚 4.article:定义文章 5.section:定义区域 6.aside:定义侧 ...
- Input 标签 安卓 与 IOS 出现圆角 显示
Input 标签 input[type="submit"],input[type="reset"],input[type="button"] ...