牛客网 球的半径和体积(模拟、清华机试)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sunlanchang/article/details/88068395

题目描述

输入球的中心点和球上某一点的坐标,计算球的半径和体积

输入描述:

球的中心点和球上某一点的坐标,以如下形式输入:x0 y0 z0 x1 y1 z1

输出描述:

输入可能有多组,对于每组输入,输出球的半径和体积,并且结果保留三位小数

为避免精度问题,PI值请使用arccos(-1)。
示例1

输入

0 0 0 1 1 1

输出

1.732 21.766

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
const double PI = acos(-1);
int main()
{
    double a, b, c, x, y, z;
    while (~scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &x, &y, &z))
    {
        double tmp = (a - x) * (a - x) + (b - y) * (b - y) + (c - z) * (c - z);
        double R = sqrt(tmp);
        double V = 4.0 / 3.0 * PI * R * R * R;
        printf("%.3lf %.3lf\n", R, V);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sunlanchang/article/details/88068395