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 ...
随机推荐
- php学习知识点框架
图片来源于知乎,感觉挺全面,通过查看可以更好的了解自己的薄弱知识点,大家共勉.
- [转]深入理解ajax系列——进度事件
一般地,使用readystatechange事件探测HTTP请求的完成.XHR2规范草案定义了进度事件Progress Events规范,XMLHttpRequest对象在请求的不同阶段触发不同类型的 ...
- 【maven】maven pom文件详解
maven pom文件详解 最近配置maven中的pom文件,maven中有些属性不太清楚,在这里记录一下 <project xmlns="http://maven.apache.or ...
- Hibernate4的注解 (持续更新范例中)
作用:使得Hibernate程序的开发大大的简化.利用注解后,可不用定义持久化类对应的*.hbm.xml,而直接以注解方式写入持久化类的实现中. 注解配置持久化类常用注解. 注解 含义和作用 @Ent ...
- NFS挂载服务具体的实施方案
1.服务器磁盘共享实施方案 第一步:安装NFS和rpc. 1. 安装nfs-utils:NFS主程序,rpcbind:PRC主程序 nfs-utils:NFS主程序,包含rpc.nfsd rpc.m ...
- MyBatis Oracle批量插入
1.oracle如何insert into 多个values https://www.cnblogs.com/mq0036/p/6370224.html?utm_source=itdadao& ...
- CSS:命名规范心得分享
一个好的命名习惯(当然这里指的并不仅仅是CSS命名).不仅可以提高开发效率,而且有益于后期修改和维护. 假设我们当前使用的命名方式都是约定成俗的,所有人都是这样写,那么你去到一个新团队,或者别人来接手 ...
- Primitive Topology
原文:Primitive Topology 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010333737/article/details/78 ...
- 深入探索WebSockets
WebSockets简介 在2008年中期,开发人员Michael Carter和Ian Hickson特别敏锐地感受到Comet在实施任何真正强大的东西时所带来的痛苦和局限. 通过在IRC和W3C邮 ...
- 笔记:投机和投资 F4NNIU
笔记:投机和投资 F4NNIU 投机是零和交易. 投资是正和博弈. 投机看是短期,只关心当下. 投资是看的长期,更关注未来. 投机容易分散注意力. 投资更关心交易外的注意力. 投机像是看运气,运气有好 ...