标签:return 优秀代码 for max its 进制 inpu c++ include
计算几何
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const double PI = acos(-1.0);
struct point
{
double x;
double y;
double z;
};
struct circle
{
point o;
double r;
} a, b;
double getlen(point a, point b)
{
double ans = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z));
return ans;
}
int main()
{
scanf("%lf%lf%lf%lf", &a.o.x, &a.o.y, &a.o.z, &a.r);
scanf("%lf%lf%lf%lf", &b.o.x, &b.o.y, &b.o.z, &b.r);
if (a.r > b.r)
swap(a, b);
double dis = getlen(a.o, b.o);
if (dis + a.r <= b.r)
{
double r = max(a.r, b.r);
double ans = 4 * PI * r * r;
printf("%.6lf", ans);
}
else if (dis < a.r + b.r && dis + a.r > b.r)
{
double angle_cosa = (a.r * a.r + dis * dis - b.r * b.r) / (2 * a.r * dis);
double angle_cosb = (b.r * b.r + dis * dis - a.r * a.r) / (2 * b.r * dis);
double len_a = a.r - a.r * angle_cosa;
double len_b = b.r - b.r * angle_cosb;
double ans = 4 * PI * (a.r * a.r + b.r * b.r);
ans -= 2 * PI * (a.r * len_a + b.r * len_b);
printf("%.6lf", ans);
}
else
{
double ans = 4 * PI * (a.r * a.r + b.r * b.r);
printf("%.6lf", ans);
}
}
python(进制转换)
def toshi(x):
if '0'<=x<='9':
return ord(x)-48
return ord(x)-ord('a')+10
def shito(x):
if 0<=x<=9:
return chr(x+48)
return chr(x-10+ord('a'))
s=input()
a,b=map(int,input().split())
ans=0
for i in s:
ans*=a
ans+=toshi(i)
if ans==0:
print(0)
pr=''
while ans>0:
pr=shito(ans%b)+pr
ans//=b
print(pr)
标签:return 优秀代码 for max its 进制 inpu c++ include
原文地址:https://www.cnblogs.com/reshuffle/p/12242314.html