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

时间:2022-07-08 13:05:47

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

学到了向量模板,写法简洁。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define clc(a,b) sizeof(a,b,sizeof(a))
#define LL long long
#include<cmath>
using namespace std;
struct node {
double dis(node);//两点距离 //向量操作
node add(node);//加
double mul(node);//乘
node mul(double);//倍
double abs();//模长
node unt();//单位化
node neg();//取反
double agl(node);//夹角,度数
bool eql(node);//向量相等
int pal(node);//向量平行 double x,y;
};
double node::dis(node a) {
return sqrt(pow(x-a.x,)+pow(y-a.y,));
} node node::add(node a) {
return {x+a.x,y+a.y};
}
double node::mul(node a) {
return x*a.x+y*a.y;
}
node node::mul(double a) {
return {x*a,y*a};
}
node node::neg() {
return {-x,-y};
} double node::abs() {
return sqrt(x*x+y*y);
}
node node::unt() {
double d=this->abs();
return {x/d,y/d};
}
double node::agl(node a) {
return acos((x*a.x+y*a.y)/(this->abs()*a.abs()));
} bool node::eql(node a) {
if(fabs(x-a.x)<1e-&&fabs(y-a.y)<1e-)return ;
return ;
}
int node::pal(node a) {
node u1=this->unt();//判断单位向量
node u2=a.unt();
if(u1.eql(u2))return ;//方向相同
if(u1.eql(u2.neg()))return -;//方向相反
return ;
} double r;
node A,B,C,O;
node AB,AC,AO; int stop() {
double a=B.dis(O);
double b=A.dis(O);
if(a<r||b<r)return ;
double c=A.dis(B);
double p=(a+b+c)/;
double s=sqrt(p*(p-a)*(p-b)*(p-c));
if(c>a&&c>b) {
if(*s/c<r)return ;
return ;
}
return ;
} int only() {
if(AC.pal(AB)==)return ;
return ;
} double root(double a,double b,double c) {
return (-b-sqrt(b*b-*a*c))/(*a);
} void getc() {
double ao=A.dis(O);
double ac=root(,-*ao*cos(AC.agl(AO)),ao*ao-r*r);
C=A.add(AC.unt().mul(ac));
} int fun(node a,node b,node c) {
if(a.add(b).pal(c)==)return ;
return ;
} int jude() {
AB= {B.x-A.x,B.y-A.y};
AO= {O.x-A.x,O.y-A.y};
if(stop())return ;
if(only())return ; getc();
node CB= {B.x-C.x,B.y-C.y};
node OC= {C.x-O.x,C.y-O.y};
if(fun(AC.neg().unt(),CB.unt(),OC.unt()))return ;
return ;
}
int main() {
int T;
scanf("%d",&T);
for(int kase=; kase<=T; kase++) {
scanf("%lf%lf%lf",&O.x,&O.y,&r);
scanf("%lf%lf%lf%lf",&A.x,&A.y,&AC.x,&AC.y);
scanf("%lf%lf",&B.x,&B.y);
printf("Case #%d: ",kase);
if(jude())printf("Yes\n");
else printf("No\n");
}
return ;
}