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);
                }
            }
        }
    }
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章