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. 依赖注入的方式(DI)

    方式: 接口注入: setter方法注入: 构造方法注入: 接口注入: public class ClassA { private InterfaceB clzB; public void doSom ...

  2. GYM 101981E(开关反转性质)

    要点 做法是删去连续的k个0或k个1,连消.消消乐的那种,网上博主用个栈\(O(n)\)就很优秀地操作了这个过程 原因是有性质:比如k=3,101000贪心地翻就能翻成000101,所以连续的k个可以 ...

  3. 【产品经理】产品经理不懂API接口是什么,怎么和程序员做朋友?

    接口不是技术经理来写吗?没接过它,一脸不清楚地节奏 开放即共享,是互联网的一个重要属性和精神.它是一种服务模式,一个特殊的产品,目前较大规模的互联网企业都有自己的开放平台. 如果把自己局限为一个功能产 ...

  4. 只需一步,DLA开启TableStore多元索引查询加速!

    一.背景介绍 Data Lake Analytics(简称DLA)在构建第一天就是支持直接关联分析Table Store(简称OTS)里的数据,实现存储计算分离架构,满足用户基于SQL接口分析Tabl ...

  5. PHPStrom直接在编辑器打开php文件

    以下是自己配置PHP+Apache的开发环境,集成环境的话要换第二种方法(看个人配置):PHPStrom 如果希望直接在编辑器打开php文件,要做以下这几步配置. 第一种:非集成环境 1 2 3 第二 ...

  6. Android学习笔记之mainfest文件中android属性

    android:allowTaskReparenting 是否允许activity更换从属的任务,比如从短信息任务 切换到浏览器任务. -------------------------------- ...

  7. 【linux配置】虚拟机配置静态IP地址

    使用VMware配置虚拟机静态IP地址 一.安装好虚拟后在菜单栏选择编辑→ 虚拟网络编辑器,打开虚拟网络编辑器对话框,选择Vmnet8 Net网络连接方式,随意设置子网IP,点击NAT设置页面,查看子 ...

  8. 确定比赛名次 HDU - 1285 (拓扑排序)

     注意点: 输入数据中可能有重复,需要进行处理! #include <stdio.h> #include <iostream> #include <cstring> ...

  9. 2-3 Numpy+Matplotlib可视化(一)

    (1)pyplot基础绘图 # -*-coding:utf-8-*- # !/usr/bin/env python # Author:@vilicute import numpy as np impo ...

  10. 如何用SPSS分析学业情绪量表数据

    如何用SPSS分析学业情绪量表数据 1.数据检验.由于问卷.量表的题目是主观判断和选择,因而难免有些人不认真填,所以,筛选出有效.高质量的数据非常关键.通常需要作如下检查:(1)是否有人回答互相矛盾, ...