Kattis - amsterdamdistance【数学】
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\n", ans);
}