Mission Impossible

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 414    Accepted Submission(s):
178

Problem Description
There are A, B, C, D four kinds of resources, A can be
obtained at any point in the X-axis. B can be obtained at any point in the
Y-axis. C and D each will only be able to achieve at a certain point. Giving the
coordinates of C and D, the coordinates of your current location. Find the
shortest path to obtain the four kinds of resources and go back.
 
Input
The first line contains the number T of test
cases(T<=150). Each of the following T lines consists of six integers cx, cy,
dx, dy, hx and hy. (cx, cy) is the coordinates of resource C, (dx, dy) is the
coordinates of resource D, (hx, hy) is the coordinates of your current
location.
All the numbers of the input are in the range [-1000, 1000].
 
Output
Your program should produce a single line for each test
case containing the length of the shortest path. The answers should be rounded
to two digits after the decimal point.
 
Sample Input
3
1 1 2 2 3 3
1 1 -1 -1 -1 -1
1 -1 1 1 -1 1
 
Sample Output
8.49
5.66
6.83
 
Author
hanshuai
 
 
题意:给你C,D两点的坐标,再给起点H的坐标,A在x轴上任意位置,B在y轴上任意位置,要求从起点出发经过A,B,C,D四点后回到起点的最小距离。
 
有点麻烦的一道题,也是照着别人博客写的,每种情况都要分析。
 
用到了镜面定理:

当坐标在轴同一侧时,对其中一个点的该坐标取反,得到的新点求距离就是镜面反射的距离。

如果在不同侧,就直接求距离

附上代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; struct Point
{
double x,y;
}h,p[]; double mins(double a,double b)
{
return a<b?a:b;
} double dis(Point a, Point b) ///两点之间的距离
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} double cale()
{
int a=,b=;
double ret=dis(h,p[a])+dis(p[a],p[b])+dis(p[b],h);
double ha,ab,bh;
bool cx=,cy=;
if(h.x*p[a].x<=||h.x*p[b].x<=||p[a].x*p[b].x<=)
cx=;
if(h.y*p[a].y<=||h.y*p[b].y<=||p[a].y*p[b].y<=)
cy=;
if(!cx&&!cy) ///三个点在同一个坐标系(看不懂后面的计算,需要自己画图理解)
{
Point t1,t2;
t1.x=h.x;
t1.y=-h.y;
t2.x=-p[a].x;
t2.y=p[a].y;
ha=ret-dis(h,p[a])+dis(t1,t2); t1.x=p[b].x;
t1.y=-p[b].y;
t2.x=-p[a].x;
t2.y=p[a].y;
ab=ret-dis(p[a],p[b])+dis(t1,t2); t1.x=p[b].x;
t1.y=-p[b].y;
t2.x=-h.x;
t2.y=h.y;
bh=ret-dis(h,p[b])+dis(t1,t2); double ans=mins(ha,mins(ab,bh)); t1.x=p[a].x;
t1.y=-p[a].y;
t2.x=-p[a].x;
t2.y=p[a].y;
ans=mins(ans,ret-dis(p[a],h)+dis(t1,h)-dis(p[a],p[b])+dis(t2,p[b]));
ans=mins(ans,ret-dis(p[a],p[b])+dis(t1,p[b])-dis(p[a],h)+dis(t2,h)); t1.x=h.x;
t1.y=-h.y;
t2.x=-h.x;
t2.y=h.y;
ans=mins(ans,ret-dis(p[a],h)+dis(t1,p[a])-dis(h,p[b])+dis(t2,p[b]));
ans=mins(ans,ret-dis(h,p[b])+dis(t1,p[b])-dis(p[a],h)+dis(t2,p[a])); t1.x=p[b].x;
t1.y=-p[b].y;
t2.x=-p[b].x;
t2.y=p[b].y;
ans=mins(ans,ret-dis(p[a],p[b])+dis(t1,p[a])-dis(h,p[b])+dis(t2,h));
ans=mins(ans,ret-dis(h,p[b])+dis(t1,h)-dis(p[a],p[b])+dis(t2,p[a])); ret=ans;
}
else if(cx==&&!cy)
{
Point tmp;
tmp.x=p[a].x;
tmp.y=-p[a].y;
ha=ret-dis(h,p[a])+dis(h,tmp);
ab=ret-dis(p[a],p[b])+dis(tmp,p[b]); tmp.x=p[b].x;
tmp.y=-p[b].y;
bh=ret-dis(h,p[b])+dis(h,tmp); ret=mins(ha,mins(ab,bh));
}
else if(!cx&&cy==)
{
Point tmp;
tmp.x=-p[a].x;
tmp.y=p[a].y;
ha=ret-dis(h,p[a])+dis(h,tmp);
ab=ret-dis(p[a],p[b])+dis(tmp,p[b]); tmp.x=-p[b].x;
tmp.y=p[b].y;
bh=ret-dis(h,p[b])+dis(h,tmp); ret=mins(ha,mins(ab,bh));
} return ret;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf",&p[].x,&p[].y,&p[].x,&p[].y,&h.x,&h.y);
printf("%.2lf\n",cale());
}
return ;
}

hdu 3272 Mission Impossible的更多相关文章

  1. ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6

    #1228 : Mission Impossible 6 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You must have seen the very famou ...

  2. Mission Impossible 6

    题目:Mission Impossible 6 题目链接:http://hihocoder.com/problemset/problem/1228 题目大意: 大概就是让我们写一个代码模拟文本编辑器的 ...

  3. 2015 ACM-ICPC国际大学生程序设计竞赛北京赛区网络赛 1002 Mission Impossible 6

    题目链接: #1228 : Mission Impossible 6 解题思路: 认真读题,细心模拟,注意细节,就没有什么咯!写这个题解就是想记录一下rope的用法,以后忘记方便复习. rope(块状 ...

  4. hihocoder 1228 Mission Impossible 6

    题意:一个模拟……大概就是模拟一个编辑文档的过程……具体的还是读题吧…… 解法:刚开场就发现的一个模拟……果断敲起来…… 要注意几点与实际编辑过程不同: 1.当用C操作标记一段字符后,只有D会改变这段 ...

  5. 2015北京网络赛B题 Mission Impossible 6

    借用大牛的一张图片:模拟 #include<cstdio> #include<cmath> #include<cstring> #include<algori ...

  6. hiho Mission Impossible 6(模拟 未提交验证。。)

    题意:模拟文本操作 思路:模拟 #include<iostream> #include<stdio.h> #include<string.h> using name ...

  7. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  8. [欧拉回路] hdu 3018 Ant Trip

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3018 Ant Trip Time Limit: 2000/1000 MS (Java/Others) ...

  9. HDU 3018 欧拉回路

    HDU - 3018 Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together ...

随机推荐

  1. Hibernate_条件查询客户列表

    分析:通过名称查询 实现: 1.在list.jsp中修改 2.修改ListCustomerServlet 首先获取cust_name,增加条件:若不为空,则模糊搜索,再调用Service方法,结果放到 ...

  2. golang之Sprintf函数

  3. 洛谷3128 [USACO15DEC]最大流Max Flow——树上差分

    题目:https://www.luogu.org/problemnew/show/P3128 树上差分.用离线lca,邻接表存好方便. #include<iostream> #includ ...

  4. bzoj 1045 [HAOI2008] 糖果传递——设变量推式子

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1045 费用流TLE. #include<iostream> #include&l ...

  5. 隐马尔可夫模型及Viterbi算法

    隐马尔可夫模型(HMM,hidden Markov model)是可用于标注问题的统计学模型,描述由隐藏的马尔可夫链随机生成观测序列的过程,属于生成模型.HMM模型主要用于语音识别,自然语言处理,生物 ...

  6. Ubuntu下安装go语言

    参考:http://golang.org/doc/install/source 1. 下载go源代码 sudo apt-get install mercurial hg clone -u releas ...

  7. typescript+react+antd基础环境搭建

    typescript+react+antd基础环境搭建(包含样式定制) tsconfig.json 配置 // 具体配置可以看上面的链接 这里module moduleResolution的配置都会影 ...

  8. vue移动端项目

    用vue mint-ui  jquery-weui写了一个移动端demo 技术栈 vue2.0 vue-router axios mint-ui jquery-weui webpack 页面截图 最后 ...

  9. TyvjP2018 「Nescafé26」小猫爬山

    P2018 「Nescafé26」小猫爬山 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 Freda和rainbow饲养了N只小猫,这天,小猫们要去爬山.经 ...

  10. 弘康人寿基于 RocketMQ 构建微服务边界总线的实践

    随着互联网+和平台化战略的兴起,各个行业的 IT 系统都在向互联网架构发展,涉及的主要技术包括微服务.消息和弹性计算等,采用微服务架构实现服务高内聚.低耦合,通过异步消息完成交易快速响应和高并发.由于 ...