三分题两道: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 ...
随机推荐
- ELK之kibana的web报错[request] Data too large, data for [<agg [2]>] would be larger than limit of
http://blog.51cto.com/11819159/1926411 ELK架构:elasticsearch+kibana+filebeat 版本信息: elasticsearch 5.2.1 ...
- fineUI表格控件各属性说明
最近在新的公司后台用fineUI,所以也稍微总结一下表格的一些属性,希望对刚入手的人有些帮助: AllowPaging 允许分页,为true时表示允许分页,表格下方会出现分页工具栏: PageSize ...
- BROCADE交换机配置
BROCADE交换机配置一 与交换机交互,可以使用三种方式: 串口 以太网口 光纤口 缺省的串口参数是:9600,N,8,1 缺省IP访问方式是: IP地址: 10.77.77.77 用户名: adm ...
- unittest框架+ HTMLTestRunner 出报告时,展示控制台信息 不同展示的参数写法 加verbosity
加verbosity参数 没有加的时候展示: 参考: 来源: https://www.cnblogs.com/tomweng/p/6609937.html 介绍: HTMLTestRunner 是 ...
- PHP5.3.8连接Sql Server SQLSRV30
PHP5.3连接SQL Server就不能用php_mssql.dll了. 网上下载了好多都不行,因为它的版本是5.2的,不能再PHP5.3中使用. 后来听说微软专门为PHP出了自己的dll. 叫做M ...
- 微信小程序之wx.requestPayment 发起微信支付
wx.requestPayment 发起微信支付 timeStamp 时间戳 nonceStr 随机字符串 package 统一下单接口返回的 prepay_id 参数值 signType 签名算法 ...
- win10下默认使用福昕打开PDF
win10为了推他的edge浏览器, 将默认的pdf打开设置为了edge浏览器, 非常令人反感, 做浏览器就好好做浏览器, 为什么要默认打开pdf? 而且修改默认为福昕后, 下次打开pdf文件, 他又 ...
- python学习(八) 异常
8.1 什么是异常 8.2 按自己的方式出错 如何引发异常,以及创建自己的异常类型. 8.2.1 raise语句 >>> raise Exception Traceback (mos ...
- Java面向对象-面向对象编程之基本概念
面向对象这个概念,每本书上的说法定义很多. 我自己根据我的经验,自己归档总结了下, 所谓面向对象,就是 以基于对象的思维去分析和解决问题,万物皆对象: 面向对象经常和面向过程放一起讨论: 这里举例, ...
- Spring Cloud Zuul 1(API 网关服务)
API网关是一个更为智能的应用服务器,它的存在就像是整个微服架构系统的门面一样,所有的外部客户端访问都需要经过它来进行调度和过滤. 它实现的功能包括:请求路由.负载均衡.校验过滤等功能. Spring ...