1577 - 球的计算

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

题目输入

输入第一行为样例数m,接下来m行每行6个整数,分别表示球心和球上一点的坐标。

题目输出

输出m行,每行2个浮点数分别表示球的半径和体积,保留到小数点后两位。

输入/输出样例

题目输入

1
0 0 0 1 0 0

题目输出

1.00 4.19

C语言解答

#include<stdio.h>
#include<math.h>
#define PI 3.14159265;
int main()
{   
	double r,s;
	int n,x1,y1,z1,x2,y2,z2;
    while(scanf("%d",&n)!=EOF)
	{
		while(n--)
		{
			scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
			r=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
			s=4*r*r*r*PI;
			printf("%.2lf %.2lf\n",r,s/3);
		}
	}   
	return 0;
}


C++解答

#include <math.h>
#include <stdio.h>
using namespace std;

const double pi = acos(-1.0);

int main()
{
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        double r;
        double ax, ay, az, x, y, z;
        scanf("%lf%lf%lf", &ax, &ay, &az);
        scanf("%lf%lf%lf", &x, &y, &z);
        r=sqrt((x-ax)*(x-ax)+(y-ay)*(y-ay)+(z-az)*(z-az));
        printf("%.2f %.2f\n", r, 4*pi*r*r*r/3);
    }
    return 0;
}

时间限制 1 秒
内存限制 32 MB
讨论 统计
上一题 下一题