ACM-ICPC Live Archive

  又是搞了一个晚上啊!!!

  总算是得到一个教训,误差总是会有的,不过需要用方法排除误差。想这题才几分钟,敲这题才半个钟,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 (几何)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. HDU - 6242:Geometry Problem(随机+几何)

    Alice is interesting in computation geometry problem recently. She found a interesting problem and s ...

  4. HDU - 6242 Geometry Problem (几何,思维,随机)

    Geometry Problem HDU - 6242 Alice is interesting in computation geometry problem recently. She found ...

  5. 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 ...

  6. 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 ...

  7. you can Solve a Geometry Problem too(hdoj1086)

    Problem Description Many geometry(几何)problems were designed in the ACM/ICPC. And now, I also prepare ...

  8. (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/ ...

  9. 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 ...

随机推荐

  1. Hackerrank--Divisibility of Power(Math)

    题目链接 You are given an array A of size N. You are asked to answer Q queries. Each query is of the for ...

  2. re模块元字符

    #元字符在re模块中有特殊意义的字符,有:^ $. * + {} [] () | \ ^$ #表示开头结尾,注意:[^]表示取反 . #点,表示任意一个字符,包括空格(一个空白字符),\t(换行符). ...

  3. 基于python爬虫的github-exploitdb漏洞库监控与下载

    基于python爬虫的github-exploitdb漏洞库监控与下载 offensive.py(爬取项目历史更新内容) #!/usr/bin/env python # -*- coding:utf- ...

  4. python实例 异常处理

    #! /usr/bin/python s=input("Input your age:") if s =="":     raise Exception(&qu ...

  5. 微信小程序之组件开发中的基础知识

    跟着视频开始小程序的项目的开发,视频中这个小程序已经上线了,可以很好的看着小程序的界面进行开发,昨天看了一下具体的需求,觉得真的细节好多啊,而且其中设计的组件的思想也是很好的,能够很好的实现代码的复用 ...

  6. 微信小程序之项目的创建

    之前就想学习一下微信小程序,只不过前段时间在学习Java中的一些线程的知识,拖了很久也没有实行这个目标,今天终于从网上找了一个完整的视频,来从头学习完整的开发流程,现在逐渐有一种想法,就是自己构建项目 ...

  7. git解决冲突的最佳方法2

    1.冲突后和远程仓库的文件进行比对的时候,善于用上图所示的按钮,会提高效率 copy all-nonconflicting changes from right to left next differ ...

  8. Git.之.安装

    Git.之.安装 参考Git官网: https://git-scm.com/book/zh/v2 我这里安装的是Window,浏览官文中的安装,如下截图(点击标红的下载) 下载好软件后,双击软件,下一 ...

  9. Leetcode5.Longest Palindromic Substring最长回文字串

    给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为1000. 示例 1: 输入: "babad" 输出: "bab" 注意: &quo ...

  10. 【花般绽放】balibali

    先放项目地址:https://github.com/1067011734/balibali 感谢无私的程序员们分享 我们边看效果边看代码 项目运行出来的效果 先看Home页面 轮播 //src\pag ...