• Kattis


    Kattis - amsterdamdistance【数学】

    这里写图片描述

    这里写图片描述

    题意

    给出两个点 算出从第一个点到第二个点的最短距离,只不过这里不是直角坐标系, 是雷达图

    思路
    因为内圈的圆的路径要比外圈的小,所以我们要尽可能先往内圈走,加一个判断条件 走到哪里就好了

    AC代码

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <cstring>
    #include <map>
    #include <stack>
    #include <set>
    #include <cstdlib>
    #include <ctype.h>
    #include <numeric>
    #include <sstream>
    using namespace std;
    
    typedef long long LL;
    const double PI  = 3.14159265358979323846264338327;
    const double E   = 2.718281828459;  
    const double eps = 1e-6;
    const int MAXN   = 0x3f3f3f3f;
    const int MINN   = 0xc0c0c0c0;
    const int maxn   = 1e5 + 5; 
    const int MOD    = 1e9 + 7;
    
    int main()
    {
        int n, m;
        double r;
        scanf("%d%d%lf", &n, &m, &r);
        double ave = r * 1.0 / m;
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        double ans = 0.0;
        ans += (max(y1, y2) - min(y1, y2)) * ave * 1.0;
        int y = min(y1, y2);
        double rec = (max(x1, x2) - min(x1, x2)) * 1.0 / n; // 份数 
        while (y)
        {
            double dis1, dis2;
            dis1 = 2.0 * ave + 1.0 * rec * (PI * (y - 1) * ave);
            dis2 = rec * PI * y * ave * 1.0;
            if (dis1 <= dis2)
            {
                ans += 2 * ave;
                y--;    
            }       
            else 
            {
                ans += dis2;
                break;  
            }                                                          
        }
        if (fabs(ans - 0.0) < eps)
            cout << 0 << endl;
        else
            printf("%.14lf
    ", ans);
    }
    
  • 相关阅读:
    hadoop20---代理另一种方式
    hadoop19---动态代理
    hadoop18---socket实现rpc
    JAVA发送HttpClient
    使用Socket&反射&Java流操作进行方法的远程调用(模拟RPC远程调用)
    hadoop17---RPC和Socket的区别
    hadoop16---反射
    hadoop15---activemq
    Struts2标签实现for循环
    struts2的标签中得到JSP脚本的变量值
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433384.html
Copyright © 2020-2023  润新知