hdu 3272 Mission Impossible
Mission Impossible
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 414 Accepted Submission(s):
178
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.
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].
case containing the length of the shortest path. The answers should be rounded
to two digits after the decimal point.
当坐标在轴同一侧时,对其中一个点的该坐标取反,得到的新点求距离就是镜面反射的距离。
如果在不同侧,就直接求距离
附上代码:
#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的更多相关文章
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6
#1228 : Mission Impossible 6 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You must have seen the very famou ...
- Mission Impossible 6
题目:Mission Impossible 6 题目链接:http://hihocoder.com/problemset/problem/1228 题目大意: 大概就是让我们写一个代码模拟文本编辑器的 ...
- 2015 ACM-ICPC国际大学生程序设计竞赛北京赛区网络赛 1002 Mission Impossible 6
题目链接: #1228 : Mission Impossible 6 解题思路: 认真读题,细心模拟,注意细节,就没有什么咯!写这个题解就是想记录一下rope的用法,以后忘记方便复习. rope(块状 ...
- hihocoder 1228 Mission Impossible 6
题意:一个模拟……大概就是模拟一个编辑文档的过程……具体的还是读题吧…… 解法:刚开场就发现的一个模拟……果断敲起来…… 要注意几点与实际编辑过程不同: 1.当用C操作标记一段字符后,只有D会改变这段 ...
- 2015北京网络赛B题 Mission Impossible 6
借用大牛的一张图片:模拟 #include<cstdio> #include<cmath> #include<cstring> #include<algori ...
- hiho Mission Impossible 6(模拟 未提交验证。。)
题意:模拟文本操作 思路:模拟 #include<iostream> #include<stdio.h> #include<string.h> using name ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- [欧拉回路] hdu 3018 Ant Trip
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3018 Ant Trip Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 3018 欧拉回路
HDU - 3018 Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together ...
随机推荐
- 论ul、ol和dl的区别
1.ul是无序列表,也就是说没有排列限制可以随意加li: <ul> <li>可以随意放置</li> <li>可以随意放置</li> < ...
- Nginx 扫盲
layout: post title: Nginx-扫盲 category: Nginx tags: [代理] Nginx 基本安装和配置文件讲解 简介 轻量级web服务器.反向代理服务 负载均衡策略 ...
- 将Factory-boy生成的复杂对象转成dict的方法
最近在做接口测试,使用Factory-boy来生成接口对象实例,接着将对象转成dict,最后通过requests发送请求. 对象转成dict,目前知道的方法就是object.__dict__ .这个方 ...
- sql server 创建视图添加表时出现从其他数据库导入的表未显示出来
创建视图添加表时出现从其他数据库导入的表未显示出来,通过数据库刷新,也不能解决.关闭SQL server management studio 后,再次进入,在创建视图的时候添加表的列表就出现了新导入的 ...
- Spring_Hibernate
Spring与Hiberante整合 通过hibernate的学习,我们知道,hibernate主要在hibernate.cfg.xml配置文件中 接下来我们看一下hibernate的一个配置文件 h ...
- 高效整洁CSS代码原则(上)
CSS学起来并不难,但在大型项目中,就变得难以管理,特别是不同的人在CSS书写风格上稍有不同,团队上就更加难以沟通,为此总结了一些如何实现高效整洁的CSS代码原则: 1. 使用Reset但并非全局Re ...
- 【水滴石穿】bstmy-blend-app
这个项目是一个简单的底部导航切换页面 项目的地址为:https://github.com/Bstmy/bstmy-blend-app 先看效果 点击首页是首页面,点击个人中心是个人中心页面 先看代码 ...
- thinkphp---display与fetch区别
区别: ① display方法直接输出模板文件渲染后的内容,fetch方法是返回模板文件渲染后的内容 ② 有时候我们不想直接输出模板内容,而是希望对内容再进行一些处理后输出, 就可以使用fetch方法 ...
- 自学FPAG笔记之 " top_down “
top_town设计:在FPGA中top_down(自顶向上)是十分重要的一种编程方法,优点:使用top_down方法去写代码会使得程序看起来十分简洁,缺点:top_down写的文件会特别多. 例子: ...
- java视频长度读取 方案参照文件
ffmpeg库 必须http://ffmpeg.org/download.html#build-windows 第三方jar sauronsoftwarehttp://www.sauronsoftwa ...