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)的更多相关文章

  1. [LightOJ1240]Point Segment Distance 题解

    题意简述 原题LightOJ 1240,Point Segment Distance(3D). 求三维空间里线段AB与C. 题解 我们设一个点在线段AB上移动,然后发现这个点与原来的C点的距离呈一个单 ...

  2. 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 ...

  3. 任务调度分配题两道 POJ 1973 POJ 1180(斜率优化复习)

    POJ 1973 这道题以前做过的.今儿重做一次.由于每个程序员要么做A,要么做B,可以联想到0/1背包(谢谢N巨).这样,可以设状态 dp[i][j]为i个程序员做j个A项目同时,最多可做多少个B项 ...

  4. 『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester

    这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...

  5. 两道人数多,课程少,query多的题

    #每天进步一点点# 来两道很相似的题目~ (智商啊智商.....) hihoCoder #1236:Scores (简单的分桶法+bitset) 2015 Beijing Online的最后一题.题目 ...

  6. FJOI2020 的两道组合计数题

    最近细品了 FJOI2020 的两道计数题,感觉抛开数据范围不清还卡常不谈里面的组合计数技巧还是挺不错的.由于这两道题都基于卡特兰数的拓展,所以我们把它们一并研究掉. 首先是 D1T3 ,先给出简要题 ...

  7. ACM/ICPC 之 Floyd范例两道(POJ2570-POJ2263)

    两道以Floyd算法为解法的范例,第二题如果数据量较大,须采用其他解法 POJ2570-Fiber Network //经典的传递闭包问题,由于只有26个公司可以采用二进制存储 //Time:141M ...

  8. ACM/ICPC 之 SPFA范例两道(POJ3268-POJ3259)

    两道以SPFA算法求解的最短路问题,比较水,第二题需要掌握如何判断负权值回路. POJ3268-Silver Cow Party //计算正逆最短路径之和的最大值 //Time:32Ms Memory ...

  9. ACM/ICPC 之 两道dijkstra练习题(ZOJ1053(POJ1122)-ZOJ1053)

    两道较为典型的单源最短路径问题,采用dijkstra解法 本来是四道练习题,后来发现后面两道用dijkstra来解的话总觉得有点冗余了,因此暂且分成三篇博客(本篇以及后两篇). ZOJ1053(POJ ...

随机推荐

  1. jenkin执行权限问题

    jenkins执行报错 stderr: Permission denied, please try again. Permission denied, please try again. Permis ...

  2. file_put_contents以及file_get_contents的用法与在使用过程中遇到的问题(PHP学习)

    对数据的操作最基本的是增删改查,file_put_contents以及file_get_contents是对文件里的数据进行存入与取出. 先上代码: <?php $str = 'hello wo ...

  3. 批处理判断是否有.net环境

    @echo off (echo 已安装.NET Framework) else (echo 未安装.NET Framework) pause>nul

  4. 求分数1+1/2+1/3+.....+1/n的值

    总结:自己理解错了的有以下几点: 1.s初始化的值是0.但数据类型最好定位double双精度类型 2.for循环里面的i<n.不要忘了等号,因为i作为分母,不能为0,所以从1开始, 3.在mai ...

  5. 微信小程序之目录结构

    小程序,功能不会太多,页面不会太多. 正常情况下,会包含首页,分类页面,个人中心页面,导航页面,其他页面等等. 我们首先要把页面结构布置好,把架子搭建好. 剩下的就是配置一些内容,小程序的基本信息,接 ...

  6. kali virtualbox

    提示需要头文件错误 C header files matching your running kernel were not found.  Refer to your distribution's ...

  7. PL/SQL 训练10--io及文件操作

    多数程序只需要通过SQL和底层数据库进行交互--有些情况,不可避免的还是会有一些场景,需要从PL/SQL给外部环境发送信息--或是从一些外部的源读入信息 --这节课介绍下面这些内置包 dbms_out ...

  8. oracle中,约束、表名、Index等的名称长度限制最大只能30个字符

    oracle中,约束.表名.Index等的名称长度限制最大只能30个字符

  9. linux安装xgboost

    在学校服务器上安装xgboost,事先我已经安装了anaconda,但是因为师兄已经装了python所以没加入到path. 网上的方法一般都要编译,另外官方的下载方法要联网..总之出了一堆错,最终还是 ...

  10. 【js与jquery】javascript中url编码与解码

    本文主要针对URI编解码的相关问题做了介绍,对Url编码中哪些字符需要编码.为什么需要编码做了详细的说明,并对比分析了Javascript 中和 编解码相关的几对函数 编码/解码 escape / u ...