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 ...
随机推荐
- 前端(jQuery)(6)-- jQuery的扩展与noConflict
1.jQuery的扩展 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- System V启动脚本启动的服务
/etc/rc.d/init.d/目录下的内容如下:这些常用的服务器都是System v的服务,要控制System V 的服务,我们可以使用以下命令 #/etc/rc.d/init.d/script ...
- R语言可视化--qplot函数
ggplot绘图系统 使用动词名词形容词构造句子的过程,将数据映射到美学属性上的过程,由层组成 绘图函数 qplot() :参数包括美学属性.几何体.面.统计.坐标系.主题这些层次. ggplot() ...
- Vue--vue中的组件、组件绑定事件和数据、私有组件、子组件,父子组件参数互传
一.公有组件以及组件的使用和特点 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- Spring使用JDBC配置具名参数
好处:若有多个参数,则不用再去对应位置?,直接对应参数名,便于维护 缺点:较为麻烦 使用具名参数时可以使用以下的方法 好处,通过实现类BeanPropertySqlParameterSource之间传 ...
- jquery 设置 html标签响应式布局
function sWidth() {//计算当前设备宽度 var widthSize; if ($(window).width() <= 640) { widthSize = $(window ...
- PCL配置即常见问题
1 下载 把与VS版本对应PCL的AllInOne包下载下来.要下对安装包,需要了解安装包的命名的含义,以下面的一个AllInOne包的名字为例. PCL-1.8.0-AllInOne-msvc ...
- Hibernate QBC 简单收集
Hibernate QBC 介绍: QBC(Query By Criteria)通过 API 来检索对象 主要由 Criteria 接口.Criterion 接口和 Exception 类组成,支持在 ...
- jquery输入框自动提示
1. 下载jar包:jquery.autocomplete.js 2. 页面内容:<script type="text/javascript" src="../jq ...
- php is_null、empty、isset的区别
isset 判断变量是否已存在 empty 判断变量是否为空或为0 is_null 判断变量是否为NULL 变量 empty is_null isset $a=”” true false true $ ...