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. 解决VS2008 调试启动特别慢

    Resolving Very Slow Symbol Loading with VS 2008 during debugging Recently, I was encountering insane ...

  2. python开发函数进阶:匿名函数

    一,匿名函数 #简单的需要用函数去解决的问题 匿名函数的函数体 只有一行#也叫lambda表达式# cal2(函数名) = lambda n(参数) : n*n(参数怎么处理,并且返回值)#参数可以有 ...

  3. MFC学习(五)常见面试题

    1:应用程序类 CTestOneApp::InitInstance 可以看做是MFC程序的入口函数,main函数隐藏在这个函数中.实际开发中一般不需要对这个类进行操作,但如果要在建立主对话框之前处理一 ...

  4. Py修行路 python基础 (十九)面向对象进阶(下)

    item系列 __slots__方法 __next__ 和 __iter__实现迭代器  析构函数 上下文管理协议 元类一.item系列 把对象操作属性模拟成字典的格式.  例如:对象名['key'] ...

  5. 3.solr学习速成之索引添加 查询 删除

    solrserver.java public class solrServer { private solrServer(){}; final static String SOLR_URL = &qu ...

  6. 第八章 数据库连接JDBC(待续)

    ············

  7. ARM六种寻址方式的汇编实现

    AREA Example,CODE,READONLY ENTRY CODE32 ;S 后缀:更新标志位CPSR ;!后缀:基址寄存器中的地址发生变化 ;LDR 从存储器中加载数据到寄存器 ;STR 从 ...

  8. leetcode812

    class Solution { public: double largestTriangleArea(vector<vector<int>>& points) { d ...

  9. Oracle11gR2_ADG管理之resinstate实战

    主库上打开闪回 SQL> select flashback_on from v$database; FLASHBACK_ON ------------------ YES 模拟断电 SQL> ...

  10. JS获取页面数据执行Ajax请求

    下面这个例子展示了如何使用js获取页面中元素的值,并且将这些值作为参数执行Ajax请求. $("#submit-task").bind("click", fun ...