hdu5572 An Easy Physics Problem(2015上海区域赛A题)

zjhl2 posted @ 2015年12月11日 19:52 with tags 计算几何 , 895 阅读

刚开始做计算几何,就拿之前上海区域赛的题目来练练吧。

比赛的时候看了题意,是haipz学长做的,当时感觉这是一道依靠模板的题目。

现在做了下,发现其实可以这么做:

1.旋转坐标,把速度方向搞成x轴正方向

2.可以直接比较Ay和r判断是否碰到圆柱。如果没碰到,直接判断射线能否到达B;如果碰到圆柱,可以直接勾股定理计算出碰撞点的坐标,然后就可以用atan2(y,x)函数求出反射方向的弧度,这时只要判断反射方向的弧度和碰撞点到B的向量的弧度是否相等就好了

注意判断弧度相等的时候别忘了考虑两弧度相减等于2pi的情况,所以我是用三角函数判断两弧度相等

#include<cstdio>
#include<iostream>
#include<cmath>
#define pi acos(-1)
#define eps 1e-3
using namespace std;
int t;
double ax,ay,bx,by,vx,vy,rx,ry,jx,jy,r;
void rotate(double &sx,double &sy,double sita)
{
    double x=sx,  y=sy;
    sx=x*cos(sita)+y*sin(sita);
    sy=y*cos(sita)-x*sin(sita);
}
void move()
{
    ax-=rx;  bx-=rx;
    ay-=ry;  by-=ry;
    rx=ry=0;
    double x,y;
    double sita=atan2(vy,vx);
    rotate(ax,ay,sita);
    rotate(bx,by,sita);
    rotate(vx,vy,sita);
    if (ay<-eps)
    {
        vy=-vy;
        ay=-ay;
        by=-by;
    }
}
bool bounce()
{
    return ay<r&&ax<0;
}
bool shoot()
{
    return fabs(ay-by)<eps&&bx>ax;
}
bool equ(double a,double b)
{
    return fabs(sin(a)-sin(b))<eps&&fabs(cos(a)-cos(b))<eps;
}
bool hit()
{
    if (!bounce())
        return shoot();
    //bounce
    if (shoot()) return bx<0;
    jy=ay;
    jx=-sqrt(r*r-ay*ay);
    double sita=atan2(jy,jx);
    sita=pi-sita;
    sita=pi-sita*2;
    return equ(atan2(by-jy,bx-jx),sita);
}
int main()
{
    scanf("%d",&t);
    int cas=0;
    while(t--)
    {
        scanf("%lf%lf%lf",&rx,&ry,&r);
        scanf("%lf%lf%lf%lf",&ax,&ay,&vx,&vy);
        scanf("%lf%lf",&bx,&by);
        move();
        //printf("%f %f %f\n",rx,ry,r); printf("%f %f %f %f\n",ax,ay,vx,vy);printf("%f %f\n",bx,by);
        printf("Case #%d: ",++cas);
        if (hit()) printf("Yes\n");else printf("No\n");
    }
}
Avatar_small
DPE Result Comilla 说:
2022年8月30日 21:50

Government of the People’s Republic of Bangladesh, Directorate of Primary Education (DPE), is going to announce PSC Result 2022 in student wide on 30th December 2022 for all divisional Grade 5 exam result with Ebtedayee Result 2022 for annual final terminal examinations, The Primary School Certificate Examination Result 2022 will be announced for both of General and Madhrsah students in division wise to all education board known as Prathomik Somaponi Result 2022. DPE Result ComillaThe DPE has successfully conducted the class 5th grade PSC and Ebtedayee Examination tests from 17th to 24th November 2022 under all education boards of Dhaka, Chittagong, Comilla, Rajshahi, Sylhet, Barisal, Jessore, Dinajpur and Madrasah Board, and the DPE Grade-5 exams are successfully conducted at all 7,194 centers across the country.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter