三分题两道:lightoj1146 Closest Distance、lightoj1240 Point Segment Distance (3D)
lightoj1146
Two men are moving concurrently, one man is moving from A to B and other man is moving from C to D. Initially the first man is at A, and the second man is at C. They maintain constant velocities such that when the first man reaches B, at the same time the second man reaches D. You can assume that A, B, C and D are 2D Cartesian co-ordinates. You have to find the minimum Euclidean distance between them along their path.
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.
Each case will contain eight integers: Ax, Ay, Bx, By, Cx, Cy, Dx, Dy. All the co-ordinates are between 0 and 100. (Ax, Ay) denotes A. (Bx, By) denotes B and so on.
Output
For each case, print the case number and the minimum distance between them along their path. Errors less than 10-6 will be ignored.
Sample Input
3
0 0 5 0 5 5 5 0
0 0 5 5 10 10 6 6
0 0 5 0 10 1 1 1
Output for Sample Input
Case 1: 0
Case 2: 1.4142135624
Case 3: 1
题意:小明从A点出发走到B点,小红从C点出发走到D点,已知小明到达B点的同时小红到达D点,还有ABCD的坐标
求小明和小红之间的最近♂距离
题解:三分时间,如果mid1比mid2距离小。那么答案肯定在l~mid2中
反之则一定在mid1~r中
然后据此随便三分个1000次,答案也就符合精度了。
蜜汁尴尬的TLE
代码如下,也是难得这么短。
- #include<cmath>
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- using namespace std;
- int t,ttt=,ax,ay,bx,by,cx,cy,dx,dy,times;
- double diss(double mid)
- {
- double x1,y1,x2,y2;
- x1=ax+(bx-ax)*mid;
- y1=ay+(by-ay)*mid;
- x2=cx+(dx-cx)*mid;
- y2=cy+(dy-cy)*mid;
- return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
- }
- int main()
- {
- scanf("%d",&t);
- while(t--)
- {
- ttt++;
- scanf("%d%d%d%d%d%d%d%d",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);
- double l=,r=,mid1,mid2;
- times=;
- while(times--)
- {
- mid1=(l+l+r)/;
- mid2=(l+r+r)/;
- double dis1=diss(mid1),dis2=diss(mid2);
- if(dis1<dis2)
- {
- r=mid2;
- }
- else
- {
- l=mid1;
- }
- }
- printf("Case %d: %.6lf\n",ttt,sqrt(diss(l)));
- }
- }
lightoj1240
Given a segment in 3D space, identified by A(x1, y1, z1), B(x2, y2, z2) and another point P(x, y, z) your task is to find the minimum possible Euclidean distance between the point P and the segment AB.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case starts with a line containing nine integers x1, y1, z1, x2, y2, z2, x, y, z. The magnitude of any integer will not be greater than 100.
Output
For each case, print the case number and the distance. Errors less than 10-6 will be ignored.
Sample Input
Output for Sample Input
2
0 0 1 0 1 1 0 1 0
0 0 0 1 1 1 0 0 1
Case 1: 1
Case 2: 0.8164965809
题意:给出三维平面上的一条线段和一个点
求点到该线段的最短距离。
题解:
这道题令学车中学的在下不胜尴尬啊,因为半个月前刚做过啊……
基础训练搬原题也是醉了。
之前是用平面几何的做法,只有70分
现在一看也是可以三分的。
同样假设一个人从A走到B
三分时间即可。
代码如下:
- #include<cmath>
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- using namespace std;
- int t,ttt,ax,ay,az,bx,by,bz,px,py,pz,times;
- double diss(double mid)
- {
- double x1,y1,z1;
- x1=ax+(bx-ax)*mid;
- y1=ay+(by-ay)*mid;
- z1=az+(bz-az)*mid;
- return (px-x1)*(px-x1)+(py-y1)*(py-y1)+(pz-z1)*(pz-z1);
- }
- int main()
- {
- scanf("%d",&t);
- while(t--)
- {
- ttt++;
- scanf("%d%d%d%d%d%d%d%d%d",&ax,&ay,&az,&bx,&by,&bz,&px,&py,&pz);
- times=;
- double l=,r=,mid1,mid2;
- while(times--)
- {
- mid1=(l+l+r)/;
- mid2=(l+r+r)/;
- double dis1=diss(mid1),dis2=diss(mid2);
- if(dis1>dis2)
- {
- l=mid1;
- }
- else
- {
- r=mid2;
- }
- }
- printf("Case %d: %.6lf\n",ttt,sqrt(diss(l)));
- }
- }
三分题两道:lightoj1146 Closest Distance、lightoj1240 Point Segment Distance (3D)的更多相关文章
- [LightOJ1240]Point Segment Distance 题解
题意简述 原题LightOJ 1240,Point Segment Distance(3D). 求三维空间里线段AB与C. 题解 我们设一个点在线段AB上移动,然后发现这个点与原来的C点的距离呈一个单 ...
- POJ P2318 TOYS与POJ P1269 Intersecting Lines——计算几何入门题两道
rt,计算几何入门: TOYS Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...
- 任务调度分配题两道 POJ 1973 POJ 1180(斜率优化复习)
POJ 1973 这道题以前做过的.今儿重做一次.由于每个程序员要么做A,要么做B,可以联想到0/1背包(谢谢N巨).这样,可以设状态 dp[i][j]为i个程序员做j个A项目同时,最多可做多少个B项 ...
- 『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester
这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...
- 两道人数多,课程少,query多的题
#每天进步一点点# 来两道很相似的题目~ (智商啊智商.....) hihoCoder #1236:Scores (简单的分桶法+bitset) 2015 Beijing Online的最后一题.题目 ...
- FJOI2020 的两道组合计数题
最近细品了 FJOI2020 的两道计数题,感觉抛开数据范围不清还卡常不谈里面的组合计数技巧还是挺不错的.由于这两道题都基于卡特兰数的拓展,所以我们把它们一并研究掉. 首先是 D1T3 ,先给出简要题 ...
- ACM/ICPC 之 Floyd范例两道(POJ2570-POJ2263)
两道以Floyd算法为解法的范例,第二题如果数据量较大,须采用其他解法 POJ2570-Fiber Network //经典的传递闭包问题,由于只有26个公司可以采用二进制存储 //Time:141M ...
- ACM/ICPC 之 SPFA范例两道(POJ3268-POJ3259)
两道以SPFA算法求解的最短路问题,比较水,第二题需要掌握如何判断负权值回路. POJ3268-Silver Cow Party //计算正逆最短路径之和的最大值 //Time:32Ms Memory ...
- ACM/ICPC 之 两道dijkstra练习题(ZOJ1053(POJ1122)-ZOJ1053)
两道较为典型的单源最短路径问题,采用dijkstra解法 本来是四道练习题,后来发现后面两道用dijkstra来解的话总觉得有点冗余了,因此暂且分成三篇博客(本篇以及后两篇). ZOJ1053(POJ ...
随机推荐
- erlang使用心跳模式启动shell
资料http://blog.yufeng.info/archives/2832 借鉴自从http://blog.csdn.net/mycwq/article/details/18306753 测试例子 ...
- JS Date日期
//日期属性var td = new Date(); alert( "getDate():" +td.getDate()+"\n" + "getDay ...
- 【转】Jmeter性能测试报告解析
Jmeter报告解析 1.Aggregate Report 解析 Aggregate Report 是 JMeter 常用的一个 Listener,中文被翻译为“聚合报告”.今天再次有同行问到这个报告 ...
- easyui tree 加载展开全部节点
$(function () { $('#tbClientListCont').tree({ checkbox: false, url: '/ashx/Client/tbClientList.ashx? ...
- 文件操作之增删改查3---文件的修改,f.replace(),在linux里的一些应用sed,with语句方法来打开一个或多个文件避免忘记关闭,python一行写的太长,怎么编写多行的规范
f.replace()with open("xxx","r",encoding="utf-8") as f: 想修改文件中间的数据,有两个办 ...
- linnx常用命令学习
ll命令就相当于ls -l. [-][rwx][r-x][r--] [-] 代表这个文件名为目录或文件(d为目录-为文件) [rwx]为:拥有人的权限(rwx为可读.可写.可执行) [r-x]为:同群 ...
- python学习(一) 基础知识
开始学习<Python基础教程> 1.2 交互式解释器 按照书上的例子敲了个最简单的print函数,居然报错: >>> print "fsdfs"Sy ...
- MFC学习(六)计算器
1 stdafx.h 所谓头文件预编译,就是把一个工程(Project)中使用的一些MFC标准头文件(如Windows.H.Afxwin.H)预先编译,以后该工程编译时,不再编译这部分头文件,仅仅使 ...
- JavaScript笔记——基础知识(一)
<Script>标签属性 <script>xxx</script>这组标签,是用于在 html 页面中插入 js 的主要方法.它主要有以下 几个属性: charse ...
- dd命令的高级应用
dd是Linux上的一个常用的命令.例如:dd if=/1.txt of=/tmp/2.txt (其中, if代表input file:of代表output file, 命令的结果就是将根目录 ...