An Easy Physics Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1430    Accepted Submission(s): 270

Problem 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
 
Source
 

题意:有一个质点位于点(x,y),初速度为(vx,vy),有一个柱子位于(ox,oy)半径为r,假设质点碰到柱子后发生弹性碰撞,问是否质点能经过(bx,by)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set> #define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define CT continue
#define SC scanf const double eps=1e-8; int dcmp(double x)
{
if(fabs(x)<eps) return 0;
else return x>0?1:-1;
} struct Point {
double x,y;
void read()
{
SC("%lf%lf",&x,&y);
}
}; struct circle{
Point o;
int r;
void read()
{
SC("%lf%lf%d",&o.x,&o.y,&r);
}
}; Point operator-(Point a,Point b)
{
return (Point){a.x-b.x,a.y-b.y};
} Point operator+(Point a,Point b)
{
return (Point){a.x+b.x,a.y+b.y};
} Point operator*(double p,Point a)
{
return (Point){a.x*p,a.y*p};
} double dot(Point a,Point b)
{
return a.x*b.x+a.y*b.y;
} double dis(Point a)
{
return sqrt(dot(a,a));
} double cross(Point a,Point b)
{
return a.x*b.y-b.x*a.y;
} Point GetLineProjection(Point P,Point A,Point B)
{
Point v=B-A;
Point ans=A+(dot(v,P-A)/dot(v,v))*v;
return ans;
} Point jiaoa,jiaob,tou;double d;
void getjiaopoint(Point pa,Point pav,circle C)
{
Point A=pa,B=pa+pav;
if(dis(C.o-B)>dis(C.o-A)){
A=pa+pav;
B=pa;
}
tou=GetLineProjection(C.o,A,B); d=dis(tou-C.o);
if(dcmp(d-C.r)<0)
{
double l=sqrt((double)C.r*C.r-d*d);
jiaoa=tou+l/dis(B-A)*(B-A);
jiaob=tou-l/dis(B-A)*(B-A);
}
} int main()
{
int cas;SC("%d",&cas);
circle C;
int kk=0;
Point pa,pb,pav;
while(cas--)
{
C.read();
pa.read();pav.read();pb.read(); getjiaopoint(pa,pav,C);
if(dcmp(d-C.r)>=0)
{
if(dcmp(cross(pb-pa,pav))==0&&dcmp(dot(pb-pa,pav))>0)
printf("Case #%d: Yes\n",++kk);
else printf("Case #%d: No\n",++kk);
CT;
} Point chap;
if(dcmp(dis(jiaoa-pa)-dis(jiaob-pa))<0) chap=jiaoa;
else chap=jiaob; int flag=0;
if(dcmp(cross(pa-pb,chap-pb))==0&&dcmp(dot(pa-pb,chap-pb))<=0)
flag=1; Point I=GetLineProjection(pa,C.o,chap);
Point pa2=pa+2*(I-pa),pa2v=chap-pa2;
if(dcmp(cross(pb-chap,pa2v))==0&&dcmp(dot(pb-chap,pa2v))<=0)
flag=1;
if(flag) printf("Case #%d: Yes\n",++kk);
else printf("Case #%d: No\n",++kk);
}
return 0;
}

  分析:

1.直接根据向量求出角度再比大小容易错(精度),可做a点关于直线的对称点a2,再判断b点是否在chap与a2该条射线上

pa

hdu 5572 An Easy Physics Problem 圆+直线的更多相关文章

  1. HDU 5572 An Easy Physics Problem (计算几何+对称点模板)

    HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...

  2. 【HDU 5572 An Easy Physics Problem】计算几何基础

    2015上海区域赛现场赛第5题. 题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意:在平面上,已知圆(O, R),点B.A(均在圆外),向量 ...

  3. HDU - 5572 An Easy Physics Problem (计算几何模板)

    [题目概述] On an infinite smooth table, there's a big round fixed cylinder and a little ball whose volum ...

  4. HDU 5572 An Easy Physics Problem【计算几何】

    计算几何的题做的真是少之又少. 之前wa以为是精度问题,后来发现是情况没有考虑全... 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意: ...

  5. HDU 5572--An Easy Physics Problem(射线和圆的交点)

    An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

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

  7. ACM 2015年上海区域赛A题 HDU 5572An Easy Physics Problem

    题意: 光滑平面,一个刚性小球,一个固定的刚性圆柱体 ,给定圆柱体圆心坐标,半径 ,小球起点坐标,起始运动方向(向量) ,终点坐标 ,问能否到达终点,小球运动中如果碰到圆柱体会反射. 学到了向量模板, ...

  8. HDU 4974 A simple water problem(贪心)

    HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...

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

随机推荐

  1. 题目15 链表中倒数第K个节点

    ///////////////////////////////////////////////////////////////////////////////////// // 5. 题目15 链表中 ...

  2. 剑指offer19:按照从外向里以顺时针的顺序依次打印出每一个数字,4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10.

    1 题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印 ...

  3. 【Python】**kwargs和takes 1 positional argument but 2 were given

    Python的函数定义中可以在参数里添加**kwargs——简单来说目的是允许添加不定参数名称的参数,并作为字典传递参数.但前提是——你必须提供参数名. 例如下述情况: class C(): def ...

  4. Spring Boot(一) 初步理解Spring Boot

    一.Spring Boot所解决的问题 Java开发十分笨重:繁多的配置.低下的开发效率.复杂的部署流程以头疼的第三方技术集成. Spring Boot的理念:习惯优于配置——项目中存在大量的配置,此 ...

  5. MangoDB CSharp Driver

    1.引用MongoDB for C# Driver 从网上下载C#访问MongoDB的驱动,得到两个DLL: MongoDB.Driver.dll MongoDB.Bson.dll 将它们引用到项目中 ...

  6. 基于MFC对话框的2048游戏

    在之前一篇<简单数字拼板游戏学习>基础上修改,地址:http://www.cnblogs.com/fwst/p/3706483.html 开发环境:Windows 7/ Visual St ...

  7. scrapy增量爬取

    ​开始接触爬虫的时候还是初学Python的那会,用的还是request.bs4.pandas,再后面接触scrapy做个一两个爬虫,觉得还是框架好,可惜都没有记录都忘记了,现在做推荐系统需要爬取一定的 ...

  8. java代码实现mock数据

    废话不多说,直接上代码. /** * 发get请求,获取文本 * * @param getUrl * @return 网页context */ public static String sendGet ...

  9. JAVA线程池例子

    用途及用法 网络请求通常有两种形式:第一种,请求不是很频繁,而且每次连接后会保持相当一段时间来读数据或者写数据,最后断开,如文件下载,网络流媒体等.另 一种形式是请求频繁,但是连接上以后读/写很少量的 ...

  10. vue项目前端限制页面长时间未操作超时退出到登录页

    之前项目超时判断是后台根据token判断的,这样判断需要请求接口才能得到返回结果,这样就出现页面没有接口请求时还可以点击,有接口请求时才会退出 现在需要做到的效果是:页面超过30分钟未操作时,无论点击 ...