ACM-ICPC 长沙现场赛 C 题 ZOJ3728(为什么我A过的数学题都是水题T_T)

Collision

Time Limit: 2 Seconds       Memory Limit: 65536 KB       Special Judge

There's a round medal fixed on an ideal smooth table, Fancy is trying to throw some coins and make them slip towards the medal to collide. There's also a round range which shares exact the same center as the round medal, and radius of the medal is strictly less than radius of the round range. Since that the round medal is fixed and the coin is a piece of solid metal, we can assume that energy of the coin will not lose, the coin will collide and then moving as reflect.

Now assume that the center of the round medal and the round range is origin ( Namely (0, 0) ) and the coin's initial position is strictly outside the round range. Given radius of the medal Rm, radius of coin r, radius of the round range R, initial position (xy) and initial speed vector (vxvy) of the coin, please calculate the total time that any part of the coin is inside the round range.

Please note that the coin might not even touch the medal or slip through the round range.

Input

There will be several test cases. Each test case contains 7 integers RmRrxyvx and vy in one line. Here 1 ≤ Rm < R ≤ 2000, 1 ≤ r ≤ 1000, R + r < |(xy)| ≤ 20000, 1 ≤ |(vxvy)| ≤ 100.

Output

For each test case, please calculate the total time that any part of the coin is inside the round range. Please output the time in one line, an absolute error not more than 1e-3 is acceptable.

Sample Input
5 20 1 0 100 0 -1
5 20 1 30 15 -1 0
Sample Output
30.000
29.394
 
 
大意 就是用半径为r的硬币去碰Rm的金牌,问在R范围内的时长。
本体的重点有三:1,硬币的半径处理,我是直接加到了Rm和R的上,然后硬币就成了点。
		2,情况讨论,用直线到原点距离分成三种
		3,就是判断方向了,方向不对直接0
代码如下:
 
 
#pragma comment(linker, "/STACK:102400000,102400000")
#include "iostream"
#include "cstring"
#include "algorithm"
#include "cmath"
#include "cstdio"
#include "sstream"
#include "queue"
#include "vector"
#include "string"
#include "stack"
#include "cstdlib"
#include "deque"
#include "fstream"
#include "map"
using namespace std;
typedef long long LL;
const int INF = 0x1fffffff;
const int MAXN = 1000;
#define eps 1e-14
const int mod = 100000007;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1


double dis(int x,int y,int vx,int vy)
{
    return (double)abs(vx*y-vy*x)/sqrt(vx*vx+vy*vy);
}


int main()
{
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    int Rm,R,r,x,y,vx,vy;
    while (scanf("%d%d%d%d%d%d%d",&Rm,&R,&r,&x,&y,&vx,&vy)!=EOF)
    {
        double dis0=sqrt(x*x+y*y);
        double y1=y+vy/1000.0;
        double x1=x+vx/1000.0;
        if (sqrt(x1*x1+y1*y1)>dis0) printf("0.000\n");//判断方向
        else
        {
            double l=dis(x,y,vx,vy);
            double v=sqrt(vx*vx+vy*vy);
            //cout<<l<<endl;
            Rm+=r;
            R+=r;
            if (l>=R) printf("0.000\n");//第一种未经过
            else
            {
                double s0=2*sqrt(R*R-l*l);
                if (l>=Rm)
                    printf("%.3lf\n",s0/v);//第二种直接穿过
                else
                {
                    double s1=s0-2*sqrt(Rm*Rm-l*l);//第三种碰撞发生
                    printf("%.3lf\n",s1/v);
                }
            }
        }
    }
}
 
 

                
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值