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 ...
随机推荐
- js 获取页面内链接
今天有同学问如何用 JS 正则表达式获取一段文本中的超链接,并对超链接进行处理,想了几分钟,写了下面的代码: var re = /https?:\/\/[\w\.:~\-\d\/]+(?:\?[\w\ ...
- 常用WebService一览表
天气预报Web服务,数据来源于中国气象局 Endpoint :http://www.webxml.com.cn/WebServices/WeatherWebService.asmx Disco ...
- java调用存储过程超时及DBCP参数配置说明
问题: 生产环境实时打标超时: 分析原因: “实时打标java服务中,只创建数据库Connection,没有关闭数据库Connection,导致数据库连接池耗尽,无 ...
- docker的网络-Container network interface(CNI)与Container network model(CNM)
Overview 目前围绕着docker的网络,目前有两种比较主流的声音,docker主导的Container network model(CNM)和社区主导的Container network in ...
- 写给新手的WebAPI实践
此篇是写给新手的Demo,用于参考和借鉴,用于发散思路.老鸟可以忽略了. 自己经常有这种情况,遇到一个新东西或难题,在了解和解决之前总是说“等搞定了一定要写篇文章记录下来”,但是当掌握了之后,就感觉好 ...
- gRPC helloworld service, RESTful JSON API gateway and swagger UI
概述 本篇博文完整讲述了如果通过 protocol buffers 定义并启动一个 gRPC 服务,然后在 gRPC 服务上提供一个 RESTful JSON API 的反向代理 gateway,最后 ...
- ASP.NET Zero--9.一个例子(2)商品分类管理-列表
1.创建实体类 参考:http://www.cnblogs.com/farb/p/4923137.html 在Core(领域层)项目下新建一个目录Entities,在此目录下新建一个Category类 ...
- jmeter连接数据库
新建一个 Thread Group: 新增 JDBC Connection Configuration: 点击新增的 JDBC Connection Configuration ,需要修改的参数包括: ...
- minSdkVersion与targetSdkVersion
targetSdkVersion是Android提供向前兼容的主要依据,在应用的targetSdkVersion没有更新之前,系统不会应用最新的行为变化 比如设置了app的targetSdkVersi ...
- pack://application:,,,/
FrameworkElementFactory gridFactory = new FrameworkElementFactory(typeof(Grid)); gridFactory.SetValu ...
题目链接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 ...
今天有同学问如何用 JS 正则表达式获取一段文本中的超链接,并对超链接进行处理,想了几分钟,写了下面的代码: var re = /https?:\/\/[\w\.:~\-\d\/]+(?:\?[\w\ ...
天气预报Web服务,数据来源于中国气象局 Endpoint :http://www.webxml.com.cn/WebServices/WeatherWebService.asmx Disco ...
问题: 生产环境实时打标超时: 分析原因: “实时打标java服务中,只创建数据库Connection,没有关闭数据库Connection,导致数据库连接池耗尽,无 ...
Overview 目前围绕着docker的网络,目前有两种比较主流的声音,docker主导的Container network model(CNM)和社区主导的Container network in ...
此篇是写给新手的Demo,用于参考和借鉴,用于发散思路.老鸟可以忽略了. 自己经常有这种情况,遇到一个新东西或难题,在了解和解决之前总是说“等搞定了一定要写篇文章记录下来”,但是当掌握了之后,就感觉好 ...
概述 本篇博文完整讲述了如果通过 protocol buffers 定义并启动一个 gRPC 服务,然后在 gRPC 服务上提供一个 RESTful JSON API 的反向代理 gateway,最后 ...
1.创建实体类 参考:http://www.cnblogs.com/farb/p/4923137.html 在Core(领域层)项目下新建一个目录Entities,在此目录下新建一个Category类 ...
新建一个 Thread Group: 新增 JDBC Connection Configuration: 点击新增的 JDBC Connection Configuration ,需要修改的参数包括: ...
targetSdkVersion是Android提供向前兼容的主要依据,在应用的targetSdkVersion没有更新之前,系统不会应用最新的行为变化 比如设置了app的targetSdkVersi ...
FrameworkElementFactory gridFactory = new FrameworkElementFactory(typeof(Grid)); gridFactory.SetValu ...