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 li布局网站导航条?使用ul li布局网站网页导航必要性
会布局的都知道网站导航条布局非常重要,可能一个导航条最终布局效果有时可以使用ul li列表标签布局,有时可以不用ul li布局,而是直接一个div盒子里直接放锚文本超链接的栏目名称,也能实现,看下图. ...
- dedecms list标签调用附加表字段--绝对成功
使用list标签调用附加表字段的时候会忽略一个地方,明明附加字段名已经添加进去了就是调用不出来 经过在网上查询了资料,说的天花乱坠,也都实践过一些,但是就是不成功鞋面介绍一下犯的低级错误在哪里 {de ...
- 洛谷 1447 [NOI2010]能量采集——容斥/推式子
题目:https://www.luogu.org/problemnew/show/P1447 1.容斥原理 求 f [ i ] 表示 gcd==i 的对数,先 f [ i ] = (n/i) * (m ...
- 复习解析嵌套json
在网络上找的一些经典的例子复习使用 一,解析嵌套json字符串,一个json字符串中嵌套另一个json字符串 { "msg": { "resCode": &qu ...
- 常用css3属性
总结一下在工作用常用到的属性设置 1.设置文本的可选择性 -webkit-user-select:none/text 2.设置背景的绘制区域 background-clip:border-box/pa ...
- Springboot 创建的maven获取resource资源下的文件的两种方式
Springboot 创建的maven项目 打包后获取resource下的资源文件的两种方式: 资源目录: resources/config/wordFileXml/wordFileRecord.xm ...
- thinkphp---display与fetch区别
区别: ① display方法直接输出模板文件渲染后的内容,fetch方法是返回模板文件渲染后的内容 ② 有时候我们不想直接输出模板内容,而是希望对内容再进行一些处理后输出, 就可以使用fetch方法 ...
- 【JZOJ4784】【NOIP2016提高A组模拟9.15】Map
题目描述 输入 输出 样例输入 4 4 2 1 2 2 3 3 2 3 4 1 2 1 4 样例输出 14 数据范围 样例解释 upd:保证原图连通. "不相交路径"的定义为不存在 ...
- SDUT-2140_判断给定图是否存在合法拓扑序列
数据结构实验之图论十:判断给定图是否存在合法拓扑序列 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定一个有向图,判 ...
- 使用cmd发送邮件
转自:http://www.cnblogs.com/fanyong/p/3498670.html 本文演示用命令行发送邮件的过程. SMTP 首先介绍下smtp协议——简单邮件传输协议 (Simple ...