zoukankan      html  css  js  c++  java
  • Angel's Journey(西安邀请赛) 简单计算几何

    “Miyane!” This day Hana asks Miyako for help again. Hana plays the part of angel on the stage show of the cultural festival, and she is going to look for her human friend, Hinata. So she must find the shortest path to Hinata’s house.

    The area where angels live is a circle, and Hana lives at the bottom of this circle. That means if the coordinates of circle’s center is (rx, ry)(rx,ry)and its radius is rr, Hana will live at (rx, ry - r)(rx,ry−r).

    Apparently, there are many difficulties in this journey. The area which is located both outside the circle and below the line y = ryy=ry is the sea, so Hana cannot pass this area. And the area inside the circle is the holy land of angels, Hana cannot pass this area neither.

    However, Miyako cannot calculate the length of the shortest path either. For the loveliest Hana in the world, please help her solve this problem!

    Input

    Each test file contains several test cases. In each test file:

    The first line contains a single integer T(1 le T le 500)T(1≤T≤500) which is the number of test cases.

    Each test case contains only one line with five integers: the coordinates of center rxrx 、 ryry, the radius rr, thecoordinates of Hinata’s house xx 、yy. The test data guarantees that y > ryy>ryand (x, y)(x,y) is out of the circle. (-10^2 le rx,ry,x,y le 10^2,0 < r le 10^2)(−102≤rx,ry,x,y≤102,0<r≤102).

    Output

    For each test case, you should print one line with your answer (please keep 44 decimal places).

    样例输入复制

    2
    1 1 1 2 2 
    1 1 1 1 3

    样例输出复制

    2.5708
    3.8264

    对于本题我们显然可以先猜出一个结论就那就是若初始点与右边的点能连成直线那么自然走直线

    else 那么就先走到切线处

    如果用正弦定理推角度的话并不是十分的好算

    但是如果我们采用极坐标的思想那么本题的代码就并不多了

    #include<bits/stdc++.h>
    using namespace std;
    
    double pi=acos(-1);
    
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            double rx,ry,x,y,r;
            double ans;
            cin>>rx>>ry>>r>>x>>y;
            x-=rx;
            y-=ry;
            if(x<0) x=-x;
            if(x>=r)
            {
                ans=sqrt((x-r)*(x-r)+y*y)+pi*r/2.0;
                printf("%.4lf
    ",ans);
            }
            else
            {
                double ang1,ang2,ang;
                ang2=atan(y/x)-acos(r/sqrt(x*x+y*y));
                ans=sqrt((x-(r*cos(ang2)))*(x-(r*cos(ang2)))+(y-(r*sin(ang2)))*(y-(r*sin(ang2))))+(ang2+pi/2.0)*r;
                printf("%.4lf
    ",ans);
            }
        }
    }
    
  • 相关阅读:
    Java Web之Tomcat
    Java Web之HTML5
    Java 读取propertoes文件
    SQL Server 触发器
    通过关闭 UseDNS和GSSAPIAuthentication选项加速 SSH登录
    数据库创建索引有什么优点和缺点
    修改查看MYSQL字符集(charset)
    MySQL 数据类型
    远程连接mysql数据库提示:ERROR 1130的解决办法
    怎么快速了解自己的MySQL服务器?
  • 原文地址:https://www.cnblogs.com/caowenbo/p/11852260.html
Copyright © 2011-2022 走看看