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 ...
随机推荐
- mac 终端 常用命令,MacOS 常用终端命令大全,mac 在当前目录打开终端
MacOS 常用终端命令大全:目录操作dircmp——比较两个目录的内容——dircmp dir1 dir2文件操作pg分页格式化显示文件内容——pg filenameod——显示非文本文件的内容—— ...
- 微信小程序 this.setData() 详解
1.定义 setData()函数用于将逻辑层数据发送到视图层,同时对应的改变this.data的值. 2.setData()参数格式 接受一个对象,以键(key)值(value)的方式改变值. 其中, ...
- dedecms list标签调用附加表字段--绝对成功
使用list标签调用附加表字段的时候会忽略一个地方,明明附加字段名已经添加进去了就是调用不出来 经过在网上查询了资料,说的天花乱坠,也都实践过一些,但是就是不成功鞋面介绍一下犯的低级错误在哪里 {de ...
- 用两个栈实现队列功能【剑指offer】
题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 程序代码: [方法一] class Solution { public: void push(int ...
- PHP 学习1.2
1. 流程控制 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv=& ...
- HDU 2639 第K大背包问题
//状态方程和01背包类似,dp[j][k]表示背包容量为j的第k大背包的值.......... //应当注意的是此时dp[j][1.....k]应当是递减的.................... ...
- zoj 1028 Flip and Shift(数学)
Flip and Shift Time Limit: 2 Seconds Memory Limit: 65536 KB This puzzle consists of a random se ...
- linux开发脚本自动部署及监控
linux开发脚本自动部署及监控 开发脚本自动部署及监控一.编写脚本自动部署反向代理.web.nfs:要求:1.部署nginx反向代理三个web服务,调度算法使用加权轮询: #!/bin/sh ngx ...
- Codeforces Round #275 (Div. 2) A. Counterexample【数论/最大公约数】
A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- IntelliJ IDEA添加过滤文件或目录(转)
在idea上使用svn后,发现即使svn窗口添加过滤正则没有忽略.iml文件的提交,安装ignore插件后没发现有svn的忽略选项,最后发现这样设置就可以了: 1.Settings→Editor→Fi ...