#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int main(){
int m,x0,x1,y0,y1,z0,z1;
cin>>m;
for(int i=0;i<m;i++){
cin>>x0>>y0>>z0>>x1>>y1>>z1;
double r=sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1)+(z0-z1)*(z0-z1));
double area=r*r*r*3.1415926*4/3;
cout<<fixed<<setprecision(2)<<r<<' '<<area<<endl;
}
}
#include<stdio.h>
#include<math.h>
#define Pi 3.1415926
int main()
{ int n,i,j,a[6]; double r,s; scanf("%d",&n); for(i=0;i<n;i++) { for(j=1;j<=6;j++) scanf("%d",&a[j]); r=sqrt((a[4]-a[1])*(a[4]-a[1])+(a[5]-a[2])*(a[5]-a[2])+(a[6]-a[3])*(a[6]-a[3])); s=4.0/3*Pi*r*r*r; printf("%.2lf %.2lf\n",r,s); }
}
//球的半径和体积
#include<stdio.h>
(737)#include<math.h>
#define PI 3.1415926
int main()
{
float x,y,z,x1,y1,z1,d,r,v;
int m,i;
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%f%f%f%f%f%f",&x,&y,&z,&x1,&y1,&z1);
d=sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
r=sqrt(d*d+(z1-z)*(z1-z));
v=(float)4/3*PI*r*r*r;
printf("%.2f %.2f\n",r,v);
}
return 0;
} import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt();
for (int i = 0; i <m; i++) {
int x1 = scanner.nextInt();
int y1 = scanner.nextInt();
int z1 = scanner.nextInt();
int x2 = scanner.nextInt();
int y2 = scanner.nextInt();
int z2 = scanner.nextInt();
double r = Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2)+Math.pow(z1-z2,2));
double v = 4.0/3*Math.PI*Math.pow(r,3);
DecimalFormat f = new DecimalFormat("0.00");
System.out.println(f.format(r)+" "+f.format(v));
}
}
} 首先pi一般使用accos(-1)代替,接着就是公式中r与result要注意数据精度问题,最后就是小数的
输出问题。
#include<iostream>
using namespace std;
(807)#include<iomanip>
#include<cmath>
(808)#define maxsize 1000000
#define pi acos(-1)
int main(){
int m;
int x1,x2,x3;
int y1,y2,y3;
double result;
double r;
cin>>m;
for(int i=0;i<m;i++){
cin>>x1>>x2>>x3>>y1>>y2>>y3;
r = sqrt((y1-x1)*(y1-x1)+(y2-x2)*(y2-x2)+(y3-x3)*(y3-x3));
result=4*pi*r*r*r/3;
// cout<<x1<<x2<<x3<<y1<<y2<<y3<<endl;
cout<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2)<<r<<" "<<result<<endl;
}
} #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
int m;
cin >> m;
for (int i = 0; i<m;i++){
int a1,a2,b1,b2,c1,c2;
cin>> a1>>b1>>c1 >> a2>>b2>>c2;
double r = sqrt(pow(double(a2-a1),2) + pow((b2-b1),2) + pow((c2-c1),2));
double area = 4*M_PI*pow(r,3)/3;
printf("%.2f %.2f",r,area);
cout << endl;
}
return 0;
} import math
m = int(input())
for i in range(m):
ball_axis = list(map(int, input().split()))
radius = math.sqrt(abs(ball_axis[3]-ball_axis[0])**2 + abs(ball_axis[4]-ball_axis[1])**2 + abs(ball_axis[5]-ball_axis[2])**2)
volume = radius**3 * math.pi * 4 / 3
print('%.2f %.2f'%(radius, volume))
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
int m;
float x1,y1,z1,x2,y2,z2;
cin>>m;
while(m--){
cin>>x1>>y1>>z1>>x2>>y2>>z2;
float r,v;
r = sqrt(pow(x2 - x1,2) + pow(y2 - y1,2) + pow(z2 - z1,2));
v = ((float)4/3) * 3.14159265 * pow(r,3);
printf("%.2f %.2f\n",r,v);
}
}
#include <cstdio>
#include <cmath>
int main(){
int m;
while(scanf("%d",&m) != EOF){
for(int i = 0; i < m; ++i){
int a,b,c; //球心坐标
int x,y,z; //球上一点坐标
float R,V;
scanf("%d %d %d",&a,&b,&c);
scanf("%d %d %d",&x,&y,&z);
R = sqrt((x-a)*(x-a) + (y-b)*(y-b) + (z-c)*(z-c) );
V = 4.0/3*3.1415926*R*R*R; //注意隐式转换,4/3是1,4.0/3才是1.33
printf("%.2f %.2f\n",R,V);
}
}
return 0;
} #include<iostream>
#include<cmath>
using namespace std;
void caculate(double x,double y,double z,double x1,double y1,double z1)
{
double x_len,y_len,z_len;
x_len = x1 - x;
y_len = y1 - y;
z_len = z1 - z;
double r = sqrt(x_len * x_len + y_len * y_len + z_len * z_len);
double v = 3.1415926 * pow(r, 3) * 4 / 3;
printf("%.2lf %.2lf",r,v);
cout << endl;
}
int main(void)
{
int m;
while(cin >> m)
{
while(m--)
{
double x,y,z;
cin >> x >> y >> z;
double x1,y1,z1;
cin >> x1 >> y1 >> z1;
caculate(x, y, z, x1, y1, z1);
}
}
return 0;
} #include <iostream>
#include <math.h>
#include <iomanip>
#define PI 3.1415926535
using namespace std;
class Point
{
public:
Point(int x,int y,int z):x(x),y(y),z(z){}
~Point(){}
int getX(){return x;}
int getY(){return y;}
int getZ(){return z;}
private:
int x,y,z;
};
int main()
{
int m;
int x0,y0,z0,x1,y1,z1;
double r,v;
cin >> m;
for(int i = 0; i < m; i++)
{
cin >> x0 >> y0 >> z0 >> x1 >> y1 >> z1;
Point R(x0,y0,z0);
Point S(x1,y1,z1);
r = sqrt(pow(S.getX() - R.getX(),2) + pow(S.getY() - R.getY(),2) + pow(S.getZ() - R.getZ(),2));
v = 4.0/3.0 * PI * pow(r,3);
cout << fixed << setprecision(2) << r << " " << v << endl;
}
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
const double pi = 3.1415926;
int main(){
int m,x1,y1,z1,x2,y2,z2;
double r;
cin >> m;
while(m--){
cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
r = sqrt( (x2-x1) * (x2-x1) + (y2-y1) * (y2-y1) + (z2-z1) * (z2-z1));
double volume = (4 * pi * r * r * r) / 3;
printf("%.2lf %.2lf\n",r,volume);
}
} import java.util.Scanner;
import static java.lang.Math.PI;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
while (m != 0) {
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double z1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
double z2 = sc.nextDouble();
Ball b = new Ball();
b.setRadius(x1, x2, y1, y2, z1, z2);
System.out.println(b.toString()); //限制精度后
m--;
}
}
}
class Geometry {
protected double side;
protected double volume;
public Geometry() {}
public void setSide(double side) {
this.side = side;
}
public double getSide() {
return side;
}
public double getVolume() {
volume = side * side * side;
return volume;
}
}
class Ball extends Geometry{
private double x1, x2, y1, y2, z1, z2;
private double radius;
private double volume;
public Ball(){}
public void setRadius(double x1, double x2, double y1, double y2, double z1, double z2) {
this.x1 = x1;
this.y1 = y1;
this.z1 = z1;
this.x2 = x2;
this.y2 = y2;
this.z2 = z2;
}
public double getRadius() {
return Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2) + Math.pow((z2 - z1), 2));
}
public double getVolume() {
return (4.0 / 3.0) * PI * Math.pow(getRadius(), 3);
}
@Override
public String toString() {
return String.format("%.2f", getRadius()) + " " + String.format("%.2f", getVolume());
}
} #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI acos(-1)
int main()
{
int m;
while(~scanf("%d", &m))
{
for(int i = 0; i < m; i++)
{
int x0, y0, z0, x, y, z;
scanf("%d%d%d%d%d%d", &x0, &y0, &z0, &x, &y, &z);
float radius = sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0) + (z - z0) * (z - z0));
float volume = 4.0 * PI * pow(radius, 3) / 3.0;
printf("%.2f %.2f\n", radius, volume);
}
}
return 0;
} #include<stdio.h>
#include<math.h>
#define PI 3.1415926
int main(void)
{
int m;
double a[3],b[3],c[3];
double r,v,sum;
while(!scanf("%d",&m))
while(getchar()!='\n')
continue;
for (int i=0;i<m;i++)
{
int j;
for (j=0;j<3;j++)
{
scanf("%lf",&a[j]);
}
for (j=0;j<3;j++)
{
scanf("%lf",&b[j]);
}
sum=0;
for (j=0;j<3;j++)
{
c[j]=(b[j]-a[j])*(b[j]-a[j]);
sum+=c[j];
}
r=sqrt(sum);
v=4.0/3.0*PI*pow(r,3);
printf("%.2f %.2f\n",r,v);
}
return 0;
} #include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(){
int m;
const double Pi=3.1415926;
cin>>m;
for(int i=0;i<m;i++){
double x1,x2,y1,y2,z1,z2,radius,volume;
cin>>x1>>y1>>z1>>x2>>y2>>z2;
radius=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1));
volume=4*Pi*radius*radius*radius/3;
cout<<fixed<<setprecision(2)<<radius<<" "<<volume<<endl;
}
return 0;
} #include<iostream>
#include<iomanip>
#include<cmath>
const double PI = 3.1415926;
using namespace std;
int main()
{
int m, i;
cin>>m;
for(i=0; i<m; i++)
{
int x, y, z, x0, y0, z0;
double r, v;
cin>>x>>y>>z>>x0>>y0>>z0;
r = sqrt( (x-x0) * (x-x0) + (y-y0) * (y-y0) + (z-z0) * (z-z0));
v = 4.0 / 3 * PI * r * r * r ;
cout<<setiosflags(ios::fixed)<<setprecision(2)<<r<<" "<<v<<endl;
}
return 0;
} /*HI LWQ
author @Rh
time@2019/9/9/13:52
*/
#include <stdio.h>
#include <math.h>
using namespace std;
#define PI 3.1415926
int main() {
int m;
int x0, x1, y0, y1, z0, z1;
while (scanf("%d", &m) != EOF) {
for (int i = 0; i< m; i++) {
scanf("%d%d%d%d%d%d", &x0, &y0, &z0, &x1, &y1, &z1);
double r = sqrt((x0 - x1)*(x0 - x1) + (y0 - y1)*(y0 - y1) + (z0 - z1)*(z0 - z1));
printf("%.2lf %.2lf\n", r, 4.0 / 3 * PI*r*r*r);
}
}
return 0;
}