题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4760
Time limit: 3000 ms

Problem Description

The 2D-solar system like our solar system comprises Bigsun (its sun) and its planetary system of many circular planets orbiting around Bigsun. Due to the high gravity of Bigsun, all planets have been attracted by Bigsun. Precisely, they orbit around Bigsun while being tangent to it as depicted in the figure (As Bigsun is so huge, its boundary looks like a line.) Surprisingly, up to the current time no two planets have collided with each other, but no one knows whether the system is free of collisions
in the future. You are to write a program to verify whether there is a possibility of any collision in the future and if so, compute the time at which the first collision happens. The scientists of NASA have realized that each planet in the 2D-solar system moves with a constant velocity. More precisely, it turned out that the motion equation of a planet can be described by the position of its touching point with the boundary of Bigsun through time by the linear equation y=at+by = at + by=at+b where a and b are two known parameters and t denotes time.

Input

There are multiple test cases in the input. Each test case starts with a line containing an integer n(n≤n≤50,000)n (n ≤ n ≤ 50, 000)n(n≤n≤50,000) where nnn is the number of planets. The iii-th line of the next nnn lines contains 333 spaceseparated integers rir_iri​, aia_iai​, and bib_ibi​ whose absolute values are not exceeding 1,000,000,0001,000,000,0001,000,000,000. The number ririri which is a positive square number, denotes the radius of Planet iii and aia_iai​ and bib_ibi​ specify its motion equation, i.e. the position of the tangent point of the planet on the boundary of Bigsun at time ttt is ait+bia_it + b_iai​t+bi​. The input terminates with a line containing ‘0’‘0’‘0’ which should not be processed.

Output

For each test case, output a line containing the time at which the first collision happens under the assumption that the current time is equal to 000 and all planets are disjoint at the current time. If the system is free of collisions you must output “Collision-Free System”. The output must be rounded to exactly two digits after the decimal point.

Sample Input

3
1 1 1
4 3 6
9 -7 30
2
4 -1 1
1 1 7
2
1 1 10
1 2 5
0

Sample Output

1.20
Collision-Free System
3.00

Problem solving report:

Description:有nnn个圆在一条直线上,直线无限长,每个圆有一个速度,可能往左,也可能往右,保证所有的圆在一开始的时候都相离。问能不能所有的圆永远都不相撞,如果相撞,输出相撞的时间。给出每个圆的半径rrr,速度aaa和起始位置bbb。
Problem solving:按照初始位置排序,那么答案必定小于等于相邻两个圆相切的情况。
注意到对于一个圆,令左端离他最近的半径比他大的圆的位置为LLL,右端离他最近的半径比他大的圆的位置为RRR,这个圆只会受到LLL到RRR这段区间的影响。
所以维护一个半径单调递减的栈即可。

Accepted Code:

/* * @Author: lzyws739307453 * @Language: C++ */
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e4 + 5;
const int inf = 0x3f3f3f3f;
struct Circle {int r, a, b;bool operator < (const Circle &s) const {return b < s.b;}
}p[MAXN];
int main() {int n;while (~scanf("%d", &n), n) {for (int i = 0; i < n; i++)scanf("%d%d%d", &p[i].r, &p[i].a, &p[i].b);sort(p, p + n);stack <Circle> S;S.push(p[0]);double min_ = inf;for (int i = 1; i < n; i++) {while (!S.empty()) {Circle q = S.top();if (q.a > p[i].a)min_ = min(min_, (p[i].b - q.b - 2 * sqrt(q.r * p[i].r)) / (q.a - p[i].a));if (q.r < p[i].r)S.pop();else break;}S.push(p[i]);}if (min_ < inf)printf("%.2lf\n", min_);else printf("Collision-Free System\n");}return 0;
}

UVALive - 2D-Solar System相关推荐

  1. unity2018新功能之——2D Animation System

    今天收到unity的邮件,然后便浏览了下2018的新特性. https://blogs.unity3d.com/cn/2018/05/02/2018-1-is-now-available/?utm_c ...

  2. 2d shader unity 阴影_Unity中实现2D光照系统

    在一些 2D 游戏中引入实时光影效果能给游戏带来非常大的视觉效果提升,亦或是利用 2D 光影实现视线遮挡机制.例如 Terraria, Starbound. 2D 光影效果需要一个动态光照系统实现, ...

  3. Google Cartographer 《Real-Time Loop Closure in 2D LIDAR SLAM》翻译 (中英对照)

    Google Cartographer <Real-Time Loop Closure in 2D LIDAR SLAM>翻译 (中英对照) 作者: Wolfgang Hess, Damo ...

  4. Java %d,%2d, %02d 各自代表什么意思

    目录 1 解释 2 举例 1 解释 Java 中由 int 型返回字符串时,经常用 String.format 方法,传入 %d,%2d, %02d 类似参数,记录下这些参数的含义. String.f ...

  5. π-Algorithmist分类题目(3)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(3) Probability ...

  6. π-Algorithmist分类题目(1)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...

  7. python一百行代码多少钱_用86行Python代码模拟太阳系

    Python代码模拟的太阳系,包括了水星(Mercury), 金星(Venus),地球(Earth),月球(Moon),火星(Mars) 上面的动画是我用86行Python代码模拟的一个比较真实的太阳 ...

  8. pixel 3 变焦_D3变焦—缺少的手册

    pixel 3 变焦 by lars verspohl 由拉斯·韦斯波尔 D3 Zoom:缺少的手册 (D3 Zoom: The Missing Manual) 如何使用SVG和Canvas缩放和平移 ...

  9. html5 运动轨迹绘画,html5 canvas行星运动轨迹动画特效

    特效描述:html5 canvas 行星运动 轨迹动画特效.html5运动轨迹,行星动画特效 代码结构 1. 引入JS 2. HTML代码 Your browser doesn't support c ...

最新文章

  1. windows8下安装Visual Studio2008
  2. open flash chart2 php,open flash chart2 图表导出到PDF,服务端语言为PHP
  3. java rect平移_如何在Java Swing中使用鼠标平移图像
  4. 对PostgreSQL cmin和cmax的理解
  5. android activity滑动切换,Android 向右滑动切换Activity, 随着手势的滑动而滑动的效果...
  6. java list转json
  7. [转载]敏捷开发,你真的做对了吗?
  8. 机器学习笔记(十四):主成分分析法(PCA)(2)
  9. dd命令烧写superboot.bin
  10. 热切换Log4j日志级别
  11. 杯具啊,混合语言编程的弊端出现了,兼谈js的开发工具
  12. jvm如何排查生产环境cpu飙高的问题
  13. 分门别类刷leetcode——动态规划(C++实现)
  14. Amcharts属性的含义
  15. docker部署rabbitmq出错touch: cannot touch ‘/etc/rabbitmq/rabbitmq.conf‘: Permission denied
  16. 相亲小程序如何做到年入百万?盈利模式是什么?
  17. MongoDB数据库的安装及使用教程
  18. 农村将迎来重大爆发!传统农业链条正在重塑,关键一步已经迈出
  19. 尚硅谷_佟刚_SpringMVC_工程实例与代码(自己敲的)
  20. Mysql数据库以及sql语言

热门文章

  1. docker网络模式与资源控制
  2. go mod拉取gitlab私有仓库代码问题最全总结
  3. 如何正确使用步道乐跑
  4. 波斯语计算机语言,语言「波斯语」10句及词汇
  5. GitHub 忘记SSH密钥
  6. [Qt] TCP客户端与服务器断开连接自动重联机制
  7. signature=cb30417dfa65eef445418827e0f0e0e6,以太坊P2P网络节点初始化
  8. CVPR 2020 Tutorial How to write a good rebuttal(如何写一篇好反驳)概要总结
  9. 亲测:一加手机3刷机OxygenOS详细教程
  10. 需要类型转换时请为模板定义非成员函数——条款46