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 ...
随机推荐
- 推荐大家自学的java学习网站,生动的讲解适合刚入门
java学习网站(不仅仅是只学习java的知识):http://how2j.cn 首先大家来看看这个网站都有些啥 首页:图中的左侧目录大家看到了,从java基础到高级,从后台技术到前端页面,数据库,还 ...
- 序列化form表单
// 序列化JSON字符串 $.fn.serializeObject = function () { let o = {}; let a = this.serializeArray(); $.each ...
- 洛谷P1569属牛的抗议 超级强力无敌弱化版
P1569 [USACO11FEB]属牛的抗议Generic Cow Prote- 题目描述 约翰家的N头奶牛聚集在一起,排成一列,正在进行一项抗议活动.第i头奶牛的理智度 为Ai,Ai可能是负数.约 ...
- Codeforces 1150E(树、线段树)
要点 括号序列平衡度即树深度的性质 相当于中序遍历,则两点间最浅的地方即是LCA的性质 线段树维护\(d(a) + d(c) - 2*d(lca(a,c))\),一层层剥,思考维护这个量需要什么,结果 ...
- pip安装依赖与生成依赖
一.安装依赖 从requirements.txt安装依赖库 pip install -r requirements 当提示权限不够时,前面加上sudo#下面就是一个requirements.txt文件 ...
- Ajax--同源策略,jsonp跨域传输原理(callback),
什么是同源策略? 阮一峰的博客 同源策略 同源策略的解决方法: 跨域传输 img 标签的src是可以引入其他域名下的图片 script标签的src属性同理 ,也可以引入其他域名下的js文件,并执行 1 ...
- Laravel访问出错错误信息:`Warning: require(/vendor/autoload.php): failed to open stream: No such file or dire
错误信息:`Warning: require(/http/www.mywakavLee.cn/bootstrap/../vendor/autoload.php): failed to open str ...
- go struct 继承
- redis数据库基本使用
redis数据库 # 1.安装redis与可视化操作工具 # 选择安装路径.圈中默认配置环境变量 # 2.在服务中管理redis服务器的开启关闭 # 3.命令行简单使用redis: -- redis- ...
- maven与sbt修改国内镜像
一.idea中的maven 1.打开IntelliJ IDEA->Settings ->Build, Execution, Deployment -> Build Tools > ...