LA 4676 Geometry Problem (几何)
又是搞了一个晚上啊!!!
总算是得到一个教训,误差总是会有的,不过需要用方法排除误差。想这题才几分钟,敲这题才半个钟,debug就用了一个晚上了!TAT
有一定几何基础的很容易想到这里的碰撞一定是其中一个顶点撞到另一个三角形的边上,于是就可以暴力枚举每一个顶点的最先碰撞的时间。注意的是,求直线相交以后,判交点是否在线段内,对于1e7的数据,千万不要判点在线上!TAT 因为已经知道是交点了,只要判断是不是在两点之间就好了。
代码如下:(把onseg改少了一个判断就过了)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath> using namespace std; const double EPS = 1e-;
const double FINF = 1e100;
template<class T> T sqr(T x) { return x * x;}
inline int sgn(double x) { return (x > EPS) - (x < -EPS);} struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
Point operator + (Point a) { return Point(x + a.x, y + a.y);}
Point operator - (Point a) { return Point(x - a.x, y - a.y);}
Point operator * (double p) { return Point(x * p, y * p);}
Point operator / (double p) { return Point(x / p, y / p);}
} ; inline double cross(Point a, Point b) { return a.x * b.y - a.y * b.x;}
inline double dot(Point a, Point b) { return a.x * b.x + a.y * b.y;}
inline double veclen(Point x) { return sqrt(dot(x, x));}
inline Point vecunit(Point x) { return x / veclen(x);} struct Line {
Point s, t;
Line() {}
Line(Point s, Point t) : s(s), t(t) {}
Point vec() { return t - s;}
Point point(double p) { return s + vec() * p;}
} ; inline bool onseg(Point x, Point a, Point b) { return sgn(dot(a - x, b - x)) <= ;}
inline Point llint(Line a, Line b) { return a.point(cross(b.vec(), a.s - b.s) / cross(a.vec(), b.vec()));} Point tri[][], v[]; double work(int a, int b) {
double ret = FINF;
Point vec = v[a] - v[b];
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
if (sgn(cross(vec, tri[b][j] - tri[b][j + ])) == ) continue;
Point ip = llint(Line(tri[a][i], tri[a][i] + vec), Line(tri[b][j], tri[b][j + ]));
if (!onseg(ip, tri[b][j], tri[b][j + ])) continue;
Point dir = ip - tri[a][i];
if (sgn(dot(dir, vec)) < ) continue;
ret = min(ret, veclen(dir) / veclen(vec));
}
}
return ret;
} inline double work() { return min(work(, ), work(, ));} int main() {
//freopen("in", "r", stdin);
int T;
cin >> T;
while (T--) {
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) cin >> tri[i][j].x >> tri[i][j].y;
tri[i][] = tri[i][];
cin >> v[i].x >> v[i].y;
}
double ans = work();
//cout << work(0, 1) << ' ' << work(1, 0) << endl;
if (ans >= FINF) puts("NO COLLISION");
else printf("%.12f\n", ans);
}
return ;
}
——written by Lyon
LA 4676 Geometry Problem (几何)的更多相关文章
- You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...
- hdu 1086 You can Solve a Geometry Problem too (几何)
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- HDU - 6242:Geometry Problem(随机+几何)
Alice is interesting in computation geometry problem recently. She found a interesting problem and s ...
- HDU - 6242 Geometry Problem (几何,思维,随机)
Geometry Problem HDU - 6242 Alice is interesting in computation geometry problem recently. She found ...
- HDU1086You can Solve a Geometry Problem too(判断线段相交)
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- hdu 1086 You can Solve a Geometry Problem too
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- you can Solve a Geometry Problem too(hdoj1086)
Problem Description Many geometry(几何)problems were designed in the ACM/ICPC. And now, I also prepare ...
- (hdu step 7.1.2)You can Solve a Geometry Problem too(乞讨n条线段,相交两者之间的段数)
称号: You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...
- HDU 1086:You can Solve a Geometry Problem too
pid=1086">You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Mem ...
随机推荐
- Java问题解读系列之String相关---String、StringBuffer、StringBuilder的区别
今天的题目是String.StringBuffer和StringBuilder的区别: 首先还是去官方的API看看对这三种类型的介绍吧,Go...... 一.继承类和实现接口情况 1.String类 ...
- IntelliJ IDEA 17 创建maven项目
参考博客: https://yq.aliyun.com/articles/111053# 部署服务器时 没有Tomcat Server选项
- LINNX查看当前登录的用户
W w命令主要是查看当前登录的用户,这个命令相对来说比较简单.我们来看一下截图. 在上面这个截图里面呢,第一列user,代表登录的用户,第二列,tty代表用户登录的终端号,因为在linux中并不是只有 ...
- 威胁快报|Nexus Repository Manager 3新漏洞已被用于挖矿木马传播,建议用户尽快修复
背景 近日,阿里云安全监测到watchbog挖矿木马使用新曝光的Nexus Repository Manager 3远程代码执行漏洞(CVE-2019-7238)进行攻击并挖矿的事件. 值得注意的是, ...
- JavaScript基本的使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Python3 中 configparser 模块用法
configparser 简介 configparser 是 Pyhton 标准库中用来解析配置文件的模块,并且内置方法和字典非常接近.Python2.x 中名为 ConfigParser,3.x 已 ...
- 每日算法之三十四:Multiply Strings
大数相乘,分别都是用字符串表示的两个大数.求相乘之后的结果表示. 首先我们应该考虑一下測试用例会有哪些,先准备測试用例对防御性编程会有比較大的帮助.可以考虑一些极端情况.有以下几种用例: 1)&quo ...
- Spring MVC使用ModelAndView进行重定向(转)
1.Servlet重定向forward与redirect: 使用servlet重定向有两种方式,一种是forward,另一种就是redirect.forward是服务器内部重定向,客户端并不知道服务器 ...
- Oracle存储过程小解
Oracle存储过程小解 1.创建语法 create or replace procedure pro_name( paramIn in type, paramOUt out type, paramI ...
- 2019-8-31-dotnet-方法名-To-和-As-有什么不同
title author date CreateTime categories dotnet 方法名 To 和 As 有什么不同 lindexi 2019-08-31 16:55:58 +0800 2 ...