HDU 5572 An Easy Physics Problem (计算几何+对称点模板)
HDU 5572 An Easy Physics Problem (计算几何)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572
Description
On an infinite smooth table, there's a big round fixed cylinder and a little ball whose volume can be ignored.
Currently the ball stands still at point A, then we'll give it an initial speed and a direction. If the ball hits the cylinder, it will bounce back with no energy losses.
We're just curious about whether the ball will pass point B after some time.
Input
First line contains an integer T, which indicates the number of test cases.
Every test case contains three lines.
The first line contains three integers Ox, Oy and r, indicating the center of cylinder is (Ox,Oy) and its radius is r.
The second line contains four integers Ax, Ay, Vx and Vy, indicating the coordinate of A is (Ax,Ay) and the initial direction vector is (Vx,Vy).
The last line contains two integers Bx and By, indicating the coordinate of point B is (Bx,By).
⋅ 1 ≤ T ≤ 100.
⋅ |Ox|,|Oy|≤ 1000.
⋅ 1 ≤ r ≤ 100.
⋅ |Ax|,|Ay|,|Bx|,|By|≤ 1000.
⋅ |Vx|,|Vy|≤ 1000.
⋅ Vx≠0 or Vy≠0.
⋅ both A and B are outside of the cylinder and they are not at same position.
Output
For every test case, you should output "Case #x: y", where x indicates the case number and counts from 1. y is "Yes" if the ball will pass point B after some time, otherwise y is "No".
Sample Input
2
0 0 1
2 2 0 1
-1 -1
0 0 1
-1 2 1 -1
1 2
Sample Output
Case #1: No
Case #2: Yes
题意:
在平面内给你一个固定的实心圆,然后从a点有一个球,给你运动方向问能否撞击到b点。
题解:
首先是能不能够撞击到大的圆。这个判断可以联立运动方程和圆的方程,产生一个一元二次方程,无解或者解小于0则是不撞击。如不能撞击到那么就判断直线运动能否撞击到b点即可。如果能撞击到,判断撞击之前能否撞到b点。如不能,将a点关于圆心与撞击点连成的直线的对称点求出,这样就可以再次判断。注意:一定不要通过普适方程求解,使用向量求解对称点,否则Wa到世界末日。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
const ld eps = 1e-10;
ld r;
int sgn(ld x){
if (fabs(x) < eps)
return 0;
return x > 0?1:-1;
}
struct Point{
ld x,y;
Point (double _x = 0, double _y = 0):x(_x), y(_y) {}
bool operator < (const Point &b) const {
return (sgn (x-b.x) == 0 ? sgn (y-b.y) < 0 : x < b.x);
}
Point operator + (const Point &b) const {
return Point (x+b.x, y+b.y);
}
Point operator - (const Point &b) const {
return Point (x-b.x, y-b.y);
}
Point operator * (double a) {
return Point (x*a, y*a);
}
Point operator / (double a) {
return Point (x/a, y/a);
}
double len2 () {//返回长度的平方
return x*x + y*y;
}
double len () {//返回长度
return sqrt (len2 ());
}
Point change_len (double r) {//转化为长度为r的向量
double l = len ();
if (sgn (l) == 0) return *this;//零向量返回自身
r /= l;
return Point (x*r, y*r);
}
};
Point a,b,c,da;
bool rig(ld x,ld y,ld dx,ld dy,ld px,ld py)
{
ld t;
if (sgn(dx) == 0){
t = (py-y)/dy ;
if (sgn(x+t*dx-px) == 0 && t >= 0)
return true;
return false;
}else {
t = (px-x)/dx;
if (sgn(y+t*dy-py) == 0 && t >= 0)
return true;
return false;
}
}
ld dot(const Point &a,const Point &b){
return a.x*b.x+a.y*b.y;
}
Point projection (Point p, Point s,Point e) {
return s + (((e-s) * dot (e-s, p-s)) / (e-s).len2() );
}
Point dc(Point p,Point s,Point e)
{
Point q = projection(p,s,e);
return Point (2*q.x-p.x, 2*q.y-p.y);
}
bool solve()
{
ld A,B,C;
A = da.x*da.x + da.y*da.y;
B = 2.0*(da.x*(a.x-c.x) + da.y*(a.y-c.y)) ;
C = (a.x-c.x)*(a.x-c.x) + (a.y-c.y)*(a.y-c.y) -r*r;
ld dlt = B*B - 4.0*A*C;
if (sgn(dlt) <= 0){
return rig(a.x,a.y,da.x,da.y,b.x,b.y);
}else {
ld t = (-B-sqrt(dlt))/A/2.0;
if (sgn(t) < 0){
return rig(a.x,a.y,da.x,da.y,b.x,b.y);
}
Point hit;
hit.x = a.x+t*da.x;
hit.y = a.y+t*da.y;
if (rig(a.x,a.y,da.x,da.y,b.x,b.y))
if (b.x >= min(hit.x,a.x) && b.x <= max(hit.x,a.x) && b.y >= min(a.y,hit.y) && b.y <= max(a.y,hit.y))
return true;
Point bb = dc(a,hit,c);
return rig(hit.x,hit.y,bb.x-hit.x,bb.y-hit.y,b.x,b.y);
}
}
int main()
{
int t;
scanf("%d",&t);
for (int _t = 1; _t <= t; _t++){
cin>>c.x>>c.y>>r;
cin>>a.x>>a.y>>da.x>>da.y;
cin>>b.x>>b.y;
printf("Case #%d: ",_t);
if (solve())
printf("Yes\n");
else printf("No\n");
}
return 0;
}
HDU 5572 An Easy Physics Problem (计算几何+对称点模板)的更多相关文章
- hdu 5572 An Easy Physics Problem 圆+直线
An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- HDU 5572 An Easy Physics Problem【计算几何】
计算几何的题做的真是少之又少. 之前wa以为是精度问题,后来发现是情况没有考虑全... 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意: ...
- HDU - 5572 An Easy Physics Problem (计算几何模板)
[题目概述] On an infinite smooth table, there's a big round fixed cylinder and a little ball whose volum ...
- 【HDU 5572 An Easy Physics Problem】计算几何基础
2015上海区域赛现场赛第5题. 题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意:在平面上,已知圆(O, R),点B.A(均在圆外),向量 ...
- 2015 ACM-ICPC 亚洲区上海站 A - An Easy Physics Problem (计算几何)
题目链接:HDU 5572 Problem Description On an infinite smooth table, there's a big round fixed cylinder an ...
- HDU 5572--An Easy Physics Problem(射线和圆的交点)
An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- ACM 2015年上海区域赛A题 HDU 5572An Easy Physics Problem
题意: 光滑平面,一个刚性小球,一个固定的刚性圆柱体 ,给定圆柱体圆心坐标,半径 ,小球起点坐标,起始运动方向(向量) ,终点坐标 ,问能否到达终点,小球运动中如果碰到圆柱体会反射. 学到了向量模板, ...
- HDU 4974 A simple water problem(贪心)
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...
- hdu 1040 As Easy As A+B
As Easy As A+B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
随机推荐
- Python自动化测试 -ConfigParser模块读写配置文件
C#之所以容易让人感兴趣,是因为安装完Visual Studio, 就可以很简单的直接写程序了,不需要做如何配置. 对新手来说,这是非常好的“初体验”, 会激发初学者的自信和兴趣. 而有些语言的开发环 ...
- linux命令——iotop
查看CPU使用情况用top,查看I/O使用情况就需要iotop.这个命令是在 kernel v2.6.20中添加,安装的时候要注意内核的版本号. iotop常用快捷键 1. 左右箭头 --> 改 ...
- 国外大师给PHP初学者的8条建议
学习一门新语言可能会是一件很艰巨的任务,最好的办法就是借鉴前辈的经验已达到事半功倍,下面就是为php新手们准备的一些经验餐. 1.从OOP开始Naramore是SourceForge员工以及PHPWo ...
- 谷歌、flick网站图片 一次性下载 javaWeb项目 多线程下载,
源码下载:http://download.csdn.net/detail/liangrui1988/5760473
- 强悍的 CSS 扩展语言 -- Sass
<div class = 'testBorder'> <p> <input/> </p> </div> 假设上面这 3 个 DOM 元素有这 ...
- PHP集成环境自定义设置PHP版本,同时运行多个php版本,700个PHP版本随时切换,一键开启常用模块。
本文采用我自己开发的纯绿色版WAMP环境(我将这个WAMP环境命名为PHPWAMP) (PHPWAMP默认集成VC,不需要单独安装) 那么什么是WAMP环境?WAMP这个词是什么意思? Windows ...
- iOS开发-OC语言 (一)oc数据类型
分享一套以前学习iOS开发时学习整理的资料,后面整套持续更新: oc数据类型 数据类型:基本数据类型.指针数据类型 基本数据类型:数值型.字符型(char).布尔型.空类型(void) 指针数据类型: ...
- mysql数据恢复问题
现象 mysql> drop database zabbix; Query OK, 104 rows affected (0.30 sec)mysql> exitBye[root@mysq ...
- codevs1002搭桥(prim)
题目描述: 这是道题题意有点迷(或者是我语文不好),但其实实际上求的就是图中连通块的个数,然后在连通块与连通块之间连边建图跑最小生成树.但是--这个图可能是不连通的--求桥的数量和总长 于是我立刻想到 ...
- iOS软件架构——架构模式(Architectural Pattern)
一个架构模式描述软件系统里的基本的结构组织或纲要.架构模式提供一些事先定义好的子系统,指定它们的责任,并给出把它们组织在一起的法则和指南.有些作者把这种架构模式叫做系统模式[STELTING02]. ...
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572
Description
On an infinite smooth table, there's a big round fixed cylinder and a little ball whose volume can be ignored.
Currently the ball stands still at point A, then we'll give it an initial speed and a direction. If the ball hits the cylinder, it will bounce back with no energy losses.
We're just curious about whether the ball will pass point B after some time.
Input
First line contains an integer T, which indicates the number of test cases.
Every test case contains three lines.
The first line contains three integers Ox, Oy and r, indicating the center of cylinder is (Ox,Oy) and its radius is r.
The second line contains four integers Ax, Ay, Vx and Vy, indicating the coordinate of A is (Ax,Ay) and the initial direction vector is (Vx,Vy).
The last line contains two integers Bx and By, indicating the coordinate of point B is (Bx,By).
⋅ 1 ≤ T ≤ 100.
⋅ |Ox|,|Oy|≤ 1000.
⋅ 1 ≤ r ≤ 100.
⋅ |Ax|,|Ay|,|Bx|,|By|≤ 1000.
⋅ |Vx|,|Vy|≤ 1000.
⋅ Vx≠0 or Vy≠0.
⋅ both A and B are outside of the cylinder and they are not at same position.
Output
For every test case, you should output "Case #x: y", where x indicates the case number and counts from 1. y is "Yes" if the ball will pass point B after some time, otherwise y is "No".
Sample Input
2
0 0 1
2 2 0 1
-1 -1
0 0 1
-1 2 1 -1
1 2
Sample Output
Case #1: No
Case #2: Yes
题意:
在平面内给你一个固定的实心圆,然后从a点有一个球,给你运动方向问能否撞击到b点。
题解:
首先是能不能够撞击到大的圆。这个判断可以联立运动方程和圆的方程,产生一个一元二次方程,无解或者解小于0则是不撞击。如不能撞击到那么就判断直线运动能否撞击到b点即可。如果能撞击到,判断撞击之前能否撞到b点。如不能,将a点关于圆心与撞击点连成的直线的对称点求出,这样就可以再次判断。注意:一定不要通过普适方程求解,使用向量求解对称点,否则Wa到世界末日。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
const ld eps = 1e-10;
ld r;
int sgn(ld x){
if (fabs(x) < eps)
return 0;
return x > 0?1:-1;
}
struct Point{
ld x,y;
Point (double _x = 0, double _y = 0):x(_x), y(_y) {}
bool operator < (const Point &b) const {
return (sgn (x-b.x) == 0 ? sgn (y-b.y) < 0 : x < b.x);
}
Point operator + (const Point &b) const {
return Point (x+b.x, y+b.y);
}
Point operator - (const Point &b) const {
return Point (x-b.x, y-b.y);
}
Point operator * (double a) {
return Point (x*a, y*a);
}
Point operator / (double a) {
return Point (x/a, y/a);
}
double len2 () {//返回长度的平方
return x*x + y*y;
}
double len () {//返回长度
return sqrt (len2 ());
}
Point change_len (double r) {//转化为长度为r的向量
double l = len ();
if (sgn (l) == 0) return *this;//零向量返回自身
r /= l;
return Point (x*r, y*r);
}
};
Point a,b,c,da;
bool rig(ld x,ld y,ld dx,ld dy,ld px,ld py)
{
ld t;
if (sgn(dx) == 0){
t = (py-y)/dy ;
if (sgn(x+t*dx-px) == 0 && t >= 0)
return true;
return false;
}else {
t = (px-x)/dx;
if (sgn(y+t*dy-py) == 0 && t >= 0)
return true;
return false;
}
}
ld dot(const Point &a,const Point &b){
return a.x*b.x+a.y*b.y;
}
Point projection (Point p, Point s,Point e) {
return s + (((e-s) * dot (e-s, p-s)) / (e-s).len2() );
}
Point dc(Point p,Point s,Point e)
{
Point q = projection(p,s,e);
return Point (2*q.x-p.x, 2*q.y-p.y);
}
bool solve()
{
ld A,B,C;
A = da.x*da.x + da.y*da.y;
B = 2.0*(da.x*(a.x-c.x) + da.y*(a.y-c.y)) ;
C = (a.x-c.x)*(a.x-c.x) + (a.y-c.y)*(a.y-c.y) -r*r;
ld dlt = B*B - 4.0*A*C;
if (sgn(dlt) <= 0){
return rig(a.x,a.y,da.x,da.y,b.x,b.y);
}else {
ld t = (-B-sqrt(dlt))/A/2.0;
if (sgn(t) < 0){
return rig(a.x,a.y,da.x,da.y,b.x,b.y);
}
Point hit;
hit.x = a.x+t*da.x;
hit.y = a.y+t*da.y;
if (rig(a.x,a.y,da.x,da.y,b.x,b.y))
if (b.x >= min(hit.x,a.x) && b.x <= max(hit.x,a.x) && b.y >= min(a.y,hit.y) && b.y <= max(a.y,hit.y))
return true;
Point bb = dc(a,hit,c);
return rig(hit.x,hit.y,bb.x-hit.x,bb.y-hit.y,b.x,b.y);
}
}
int main()
{
int t;
scanf("%d",&t);
for (int _t = 1; _t <= t; _t++){
cin>>c.x>>c.y>>r;
cin>>a.x>>a.y>>da.x>>da.y;
cin>>b.x>>b.y;
printf("Case #%d: ",_t);
if (solve())
printf("Yes\n");
else printf("No\n");
}
return 0;
}
An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
计算几何的题做的真是少之又少. 之前wa以为是精度问题,后来发现是情况没有考虑全... 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意: ...
[题目概述] On an infinite smooth table, there's a big round fixed cylinder and a little ball whose volum ...
2015上海区域赛现场赛第5题. 题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意:在平面上,已知圆(O, R),点B.A(均在圆外),向量 ...
题目链接:HDU 5572 Problem Description On an infinite smooth table, there's a big round fixed cylinder an ...
An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
题意: 光滑平面,一个刚性小球,一个固定的刚性圆柱体 ,给定圆柱体圆心坐标,半径 ,小球起点坐标,起始运动方向(向量) ,终点坐标 ,问能否到达终点,小球运动中如果碰到圆柱体会反射. 学到了向量模板, ...
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...
As Easy As A+B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
C#之所以容易让人感兴趣,是因为安装完Visual Studio, 就可以很简单的直接写程序了,不需要做如何配置. 对新手来说,这是非常好的“初体验”, 会激发初学者的自信和兴趣. 而有些语言的开发环 ...
查看CPU使用情况用top,查看I/O使用情况就需要iotop.这个命令是在 kernel v2.6.20中添加,安装的时候要注意内核的版本号. iotop常用快捷键 1. 左右箭头 --> 改 ...
学习一门新语言可能会是一件很艰巨的任务,最好的办法就是借鉴前辈的经验已达到事半功倍,下面就是为php新手们准备的一些经验餐. 1.从OOP开始Naramore是SourceForge员工以及PHPWo ...
源码下载:http://download.csdn.net/detail/liangrui1988/5760473
<div class = 'testBorder'> <p> <input/> </p> </div> 假设上面这 3 个 DOM 元素有这 ...
本文采用我自己开发的纯绿色版WAMP环境(我将这个WAMP环境命名为PHPWAMP) (PHPWAMP默认集成VC,不需要单独安装) 那么什么是WAMP环境?WAMP这个词是什么意思? Windows ...
分享一套以前学习iOS开发时学习整理的资料,后面整套持续更新: oc数据类型 数据类型:基本数据类型.指针数据类型 基本数据类型:数值型.字符型(char).布尔型.空类型(void) 指针数据类型: ...
现象 mysql> drop database zabbix; Query OK, 104 rows affected (0.30 sec)mysql> exitBye[root@mysq ...
题目描述: 这是道题题意有点迷(或者是我语文不好),但其实实际上求的就是图中连通块的个数,然后在连通块与连通块之间连边建图跑最小生成树.但是--这个图可能是不连通的--求桥的数量和总长 于是我立刻想到 ...
一个架构模式描述软件系统里的基本的结构组织或纲要.架构模式提供一些事先定义好的子系统,指定它们的责任,并给出把它们组织在一起的法则和指南.有些作者把这种架构模式叫做系统模式[STELTING02]. ...