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 ...
随机推荐
- 图像资源Images Assets
图像资源Images Assets 开始之前,首先回顾一下iOS7初体验(1)——第一个应用程序HelloWorld中的一张图,如下所示: 本文便分享一下Images.xcassets的体验~_~ 1 ...
- linux下安装PHP5.5
下载安装包后,在安装php之前必须先安装libxml2,因此可以通过下载libxml2安装包,编译安装 我通过yum -y install libxml2 libxml2-devel(不安装这个的话, ...
- codeforces 6A. Triangle
A. Triangle time limit per test 2 seconds memory limit per test 64 megabytes input standard input ou ...
- Facebook开源的基于SQL的操作系统检测和监控框架:osquery Table详解
写在前面 上一篇介绍了osquery的一些用法,即如何使用SQL语句查询系统信息.本文就来介绍下这个table是如何定义的,及table中的数据是如何取得的. 本文以uptime和process两张表 ...
- 关于在freemarker模板中遍历数据模型List<JavaBean>的经验
本文采用简单的servlet作为后台处理数据的工具,前台使用freemarker的ftl模板作为输出工具,简单说明怎样将封装有实体类对象的List集合注入到ftl模板中并且成功的在遍历显示出来,之前在 ...
- js获取菲波那契数列的第N个元素
菲波那契数列,大致可以描叙为a(n) = a(n-1) + a(n-2) (a >=2).类似于这样[1, 1, 2, 3, 5, 8, 13 ...]. 具体大家可以百度一下.下面我们来用js ...
- js中的document.body.scrollTop与document.documentElement.scrollTop
获取当前页面滚动条纵坐标的位置:document.body.scrollTop与document.documentElement.scrollTop获取当前页面滚动条横坐标的位置:document.b ...
- 如何在标题栏的title前添加网站logo
之前在哪个网上看到的,今天没事给写下来了: 1.将像素大小为16*16的图片命名为 favicon.ico,(图片使用的颜色好像不能超过16色),放到网站根目录下就可以了; 2.在head标签中添加代 ...
- 浅谈 Linux
1969年,美国贝尔实验室的肯-汤普森在DEC PDP-7机器上开发出了UNIX系统. 1971年,肯-汤普森的同事丹尼斯-里奇发明了C语言:1973年,UNIX系统的绝大部分源 ...
- hdu1040
#include<stdio.h>#include<stdlib.h>int a[100];int cmp(const void *a,const void *b){ retu ...
题目链接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 ...
图像资源Images Assets 开始之前,首先回顾一下iOS7初体验(1)——第一个应用程序HelloWorld中的一张图,如下所示: 本文便分享一下Images.xcassets的体验~_~ 1 ...
下载安装包后,在安装php之前必须先安装libxml2,因此可以通过下载libxml2安装包,编译安装 我通过yum -y install libxml2 libxml2-devel(不安装这个的话, ...
A. Triangle time limit per test 2 seconds memory limit per test 64 megabytes input standard input ou ...
写在前面 上一篇介绍了osquery的一些用法,即如何使用SQL语句查询系统信息.本文就来介绍下这个table是如何定义的,及table中的数据是如何取得的. 本文以uptime和process两张表 ...
本文采用简单的servlet作为后台处理数据的工具,前台使用freemarker的ftl模板作为输出工具,简单说明怎样将封装有实体类对象的List集合注入到ftl模板中并且成功的在遍历显示出来,之前在 ...
菲波那契数列,大致可以描叙为a(n) = a(n-1) + a(n-2) (a >=2).类似于这样[1, 1, 2, 3, 5, 8, 13 ...]. 具体大家可以百度一下.下面我们来用js ...
获取当前页面滚动条纵坐标的位置:document.body.scrollTop与document.documentElement.scrollTop获取当前页面滚动条横坐标的位置:document.b ...
之前在哪个网上看到的,今天没事给写下来了: 1.将像素大小为16*16的图片命名为 favicon.ico,(图片使用的颜色好像不能超过16色),放到网站根目录下就可以了; 2.在head标签中添加代 ...
1969年,美国贝尔实验室的肯-汤普森在DEC PDP-7机器上开发出了UNIX系统. 1971年,肯-汤普森的同事丹尼斯-里奇发明了C语言:1973年,UNIX系统的绝大部分源 ...
#include<stdio.h>#include<stdlib.h>int a[100];int cmp(const void *a,const void *b){ retu ...