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 ...
随机推荐
- 让footer始终待在页面底部
1.把html和body的height属性设为100%;保证content的高度能撑满浏览器; 2.把#content的高度也设置为100% ,但是这里我们使用了“min-height”属性,而不是的 ...
- Socket与TcpClient的区别
原文:Socket与TcpClient的区别 Socket和TcpClient有什么区别 原文:http://wxwinter.spaces.live.com/blog/cns!C36588978AF ...
- python基础--模块的查找顺序以及相对导入和绝对导入
模块:模块是一系列功能的结合体 模块的来源: 内置的模块(python解释器自带的) 第三方(开发者编写的模块) 自定义的模块(自己编写的模块) 模块的四种表现形式: 1.使用python编写的py文 ...
- golang之if
1.if语句 (1)if (2)if else (3)if esle ...else
- Lavavel 程序报错 MassAssignmentException in Model.php line 452: _token
Lavarel 用类似于下面命令插入数据时候出错 Comment::create($request->all()) 错误页面截图如下: 错误原因:下面这行代码应该写到对应的Model里面,而不是 ...
- Openck_Swift源代码分析——添加、删除设备时算法详细的实现过程
1 初始加入设备后.上传Object的详细流程 前几篇博客中,我们讲到环的基本原理即详细的实现过程,加入我们在初始创建Ring是执行例如以下几条命令: •swift-ring-builder obj ...
- QT加载qss
QString CommonHelper::setStyle(const QString &style) { QByteArray str; QFile qss(style); qss.ope ...
- MySQL数据库操作语句(补充1)(cmd环境运行)
一.字符串类型 enum枚举类型 /* 也叫做枚举类型,类似于单选! 如果某个字段的值只能从某几个确定的值中进行选择,一般就使用enum类型, 在定义的时候需要将该字段所有可能的选项都罗列出来: */ ...
- 【JZOJ4924】【NOIP2017提高组模拟12.17】向再见说再见
题目描述 数据范围 =w= 设h[i]表示,甲队得到i分的方案数. 那么h[(n+k)/2]和h[(n−k)/2]就是答案. 设g[i]表示,甲队得到至少i分的方案数. 那么h[i]=g[i]−∑j& ...
- 大数据技术之Zookeeper
第1章 Zookeeper入门 1.1 概述 Zookeeper是一个开源的分布式的,为分布式应用提供协调服务的Apache项目. 1.2 特点 1.3 数据结构 1.4 应用场景 提供的服务包括:统 ...