ACM-ICPC Live Archive

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

  总算是得到一个教训,误差总是会有的,不过需要用方法排除误差。想这题才几分钟,敲这题才半个钟,debug就用了一个晚上了!TAT

  有一定几何基础的很容易想到这里的碰撞一定是其中一个顶点撞到另一个三角形的边上,于是就可以暴力枚举每一个顶点的最先碰撞的时间。注意的是,求直线相交以后,判交点是否在线段内,对于1e7的数据,千万不要判点在线上!TAT 因为已经知道是交点了,只要判断是不是在两点之间就好了。

代码如下:(把onseg改少了一个判断就过了)

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <cstdio>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. const double EPS = 1e-;
  10. const double FINF = 1e100;
  11. template<class T> T sqr(T x) { return x * x;}
  12. inline int sgn(double x) { return (x > EPS) - (x < -EPS);}
  13.  
  14. struct Point {
  15. double x, y;
  16. Point() {}
  17. Point(double x, double y) : x(x), y(y) {}
  18. Point operator + (Point a) { return Point(x + a.x, y + a.y);}
  19. Point operator - (Point a) { return Point(x - a.x, y - a.y);}
  20. Point operator * (double p) { return Point(x * p, y * p);}
  21. Point operator / (double p) { return Point(x / p, y / p);}
  22. } ;
  23.  
  24. inline double cross(Point a, Point b) { return a.x * b.y - a.y * b.x;}
  25. inline double dot(Point a, Point b) { return a.x * b.x + a.y * b.y;}
  26. inline double veclen(Point x) { return sqrt(dot(x, x));}
  27. inline Point vecunit(Point x) { return x / veclen(x);}
  28.  
  29. struct Line {
  30. Point s, t;
  31. Line() {}
  32. Line(Point s, Point t) : s(s), t(t) {}
  33. Point vec() { return t - s;}
  34. Point point(double p) { return s + vec() * p;}
  35. } ;
  36.  
  37. inline bool onseg(Point x, Point a, Point b) { return sgn(dot(a - x, b - x)) <= ;}
  38. inline Point llint(Line a, Line b) { return a.point(cross(b.vec(), a.s - b.s) / cross(a.vec(), b.vec()));}
  39.  
  40. Point tri[][], v[];
  41.  
  42. double work(int a, int b) {
  43. double ret = FINF;
  44. Point vec = v[a] - v[b];
  45. for (int i = ; i < ; i++) {
  46. for (int j = ; j < ; j++) {
  47. if (sgn(cross(vec, tri[b][j] - tri[b][j + ])) == ) continue;
  48. Point ip = llint(Line(tri[a][i], tri[a][i] + vec), Line(tri[b][j], tri[b][j + ]));
  49. if (!onseg(ip, tri[b][j], tri[b][j + ])) continue;
  50. Point dir = ip - tri[a][i];
  51. if (sgn(dot(dir, vec)) < ) continue;
  52. ret = min(ret, veclen(dir) / veclen(vec));
  53. }
  54. }
  55. return ret;
  56. }
  57.  
  58. inline double work() { return min(work(, ), work(, ));}
  59.  
  60. int main() {
  61. //freopen("in", "r", stdin);
  62. int T;
  63. cin >> T;
  64. while (T--) {
  65. for (int i = ; i < ; i++) {
  66. for (int j = ; j < ; j++) cin >> tri[i][j].x >> tri[i][j].y;
  67. tri[i][] = tri[i][];
  68. cin >> v[i].x >> v[i].y;
  69. }
  70. double ans = work();
  71. //cout << work(0, 1) << ' ' << work(1, 0) << endl;
  72. if (ans >= FINF) puts("NO COLLISION");
  73. else printf("%.12f\n", ans);
  74. }
  75. return ;
  76. }

——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. mac 终端 常用命令,MacOS 常用终端命令大全,mac 在当前目录打开终端

    MacOS 常用终端命令大全:目录操作dircmp——比较两个目录的内容——dircmp dir1 dir2文件操作pg分页格式化显示文件内容——pg filenameod——显示非文本文件的内容—— ...

  2. 微信小程序 this.setData() 详解

    1.定义 setData()函数用于将逻辑层数据发送到视图层,同时对应的改变this.data的值. 2.setData()参数格式 接受一个对象,以键(key)值(value)的方式改变值. 其中, ...

  3. dedecms list标签调用附加表字段--绝对成功

    使用list标签调用附加表字段的时候会忽略一个地方,明明附加字段名已经添加进去了就是调用不出来 经过在网上查询了资料,说的天花乱坠,也都实践过一些,但是就是不成功鞋面介绍一下犯的低级错误在哪里 {de ...

  4. 用两个栈实现队列功能【剑指offer】

    题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 程序代码: [方法一] class Solution { public: void push(int ...

  5. PHP 学习1.2

    1. 流程控制 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv=& ...

  6. HDU 2639 第K大背包问题

    //状态方程和01背包类似,dp[j][k]表示背包容量为j的第k大背包的值.......... //应当注意的是此时dp[j][1.....k]应当是递减的.................... ...

  7. zoj 1028 Flip and Shift(数学)

    Flip and Shift Time Limit: 2 Seconds      Memory Limit: 65536 KB This puzzle consists of a random se ...

  8. linux开发脚本自动部署及监控

    linux开发脚本自动部署及监控 开发脚本自动部署及监控一.编写脚本自动部署反向代理.web.nfs:要求:1.部署nginx反向代理三个web服务,调度算法使用加权轮询: #!/bin/sh ngx ...

  9. Codeforces Round #275 (Div. 2) A. Counterexample【数论/最大公约数】

    A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  10. IntelliJ IDEA添加过滤文件或目录(转)

    在idea上使用svn后,发现即使svn窗口添加过滤正则没有忽略.iml文件的提交,安装ignore插件后没发现有svn的忽略选项,最后发现这样设置就可以了: 1.Settings→Editor→Fi ...