# 四面体表面积

16

## 挑战

### 例

``````# input (format is up to you, see clarification above)
[23822, 47484, 57901]
[3305, 23847, 42159]
[19804, 11366, 14013]
[52278, 28626, 52757]

# output
2932496435.95
``````

stokastic 2014年

@phosgene我想阅读输入内容是挑战的一部分，所以我要说不。在未来的挑战中，我将尽量宽容输入规范。
stokastic，2014年

@JamesWilliams发布的示例不规则。但是，您的程序应处理任何输入，包括常规四面体。
2014年

5

## Python，198 178 161个字符

``````V=eval('input(),'*4)
A=0
for i in range(4):F=V[:i]+V[i+1:];a,b,c=map(lambda e:sum((a-b)**2for a,b in zip(*e)),zip(F,F[1:]+F));A+=(4*a*b-(a+b-c)**2)**.5
print A/4
``````

4

# Matlab /八度103

``````%input
[23822, 47484, 57901;
3305, 23847, 42159;
19804, 11366, 14013;
52278, 28626, 52757]

%actual code
c=input('');
a=0;
for i=1:4;
d=c;d(i,:)=[];
d=d(1:2,:)-[1 1]'*d(3,:);
a=a+norm(cross(d(1,:),d(2,:)))/2;
end
a
``````

DavidC 2014年

DavidC 2014年

DavidC 2014年

4

## APL，59

``````f←{+.×⍨⊃1 2-.⌽(⊂⍵)×1 2⌽¨⊂⍺}
.5×.5+.*⍨(f/2-/x),2f/4⍴x←⎕⎕⎕-⊂⎕
``````

``````                        ⊂⍺   # Wrap the argument in a scalar
1 2⌽¨     # Create an array of 2 arrays, by rotating `⊂⍺` by 1 and 2 places
(⊂⍵)×           # Coordinate-wise multiply each of them with the other argument
1 2-.⌽               # This is a shorthand for:
1 2  ⌽               #   Rotate the first array item by 1 and the second by 2
-.                #   Then subtract the second from the first, coordinate-wise
⊃                     # Unwrap the resulting scalar to get the (sorta) cross product
+.×                       # Calculate the dot product of that...
⍨                      # ...with itself
f←{+.×⍨⊃1 2-.⌽(⊂⍵)×1 2⌽¨⊂⍺} # Assign function to `f`
``````

``````                         ⎕⎕⎕-⊂⎕ # Take 4 array inputs, create an array of arrays by subtracting one of them from the other 3
x←        # Assign that to x
4⍴          # Duplicate the first item and append to the end
2f/            # Apply f to each consecutive pair
2-/x                 # Apply subtraction to consecutive pairs in x
f/                     # Apply f to the 2 resulting arrays
(f/2-/x),2f/4⍴x←⎕⎕⎕-⊂⎕ # Concatenate to an array of 4 squared cross products
.5+.*⍨                        # Again a shorthand for:
.5  *⍨                        #   Take square root of each element (by raising to 0.5)
+.                          #   And sum the results
.5×                              # Finally, divide by 2 to get the answer
``````

@flawr我通常这样做是因为在APL中打高尔夫球主要归结于算法设计，并且很可能会导致不常见的问题解决方法。但是我感觉像“计算叉积”在这里传达了关于算法的足够信息。如果您需要全面的说明，我将在今天晚些时候进行。
TwiNight

3

# Python 3中，308 298 292 279 258 254

``````from itertools import*
def a(t,u,v):w=(t+u+v)/2;return(w*(w-t)*(w-u)*(w-v))**.5
z,x,c,v,b,n=((lambda i,j:(sum((i[x]-j[x])**2for x in[0,1,2]))**.5)(x[0],x[1])for*x,in combinations([eval(input())for i in">"*4],2))
print(a(z,x,v)+a(z,c,b)+a(b,v,n)+a(x,c,n))
``````

• 勾股定理（3D）计算出每行的长度
• 苍鹭公式，计算出每个三角形的面积

1

2014年

1
`for i in">"*4`很聪明
2014年

2014年

1

Snorfalorpagus，2014年

1

Beta Decay

2

# 数学168 154

``````t = Subsets; p = Table[Input[], {4}];
f@{a_, b_, c_} := Module[{s = (a + b + c)/2}, N[Sqrt[s (s - #) (s - #2) (s -#3)] &[a, b, c], 25]]
Tr[f /@ (EuclideanDistance @@@ t[#, {2}] & /@ t[p, {3}])]
``````

``````p = Table[Input[], {4}];
N[Tr[Area /@ Polygon /@ Subsets[p, {3}]], 25]
``````

1

## 贤者– 103

``print sum((x*x*y*y-x*y*x*y)^.5for x,y in map(differences,Combinations(eval('vector(input()),'*4),3)))/2``

0

## Python-260

``````import copy,math
P=[input()for i in"1234"]
def e(a, b):return math.sqrt(sum([(b[i]-a[i])**2 for i in range(3)]))
o=0
for j in range(4):p=copy.copy(P);p.pop(j);a,b,c=[e(p[i],p[(i+1)%3])for i in range(3)];s=(a+b+c)/2;A=math.sqrt(s*(s-a)*(s-b)*(s-c));o+=A
print o
``````

4

Blackhole，2014年

Wrzlprmft

0

# C，303

`scanf` 无论您使用空格或换行符分隔输入，其工作方式都相同，因此您可以将其格式化为任意多行。

``````#define F ;for(i=0;i<12;i++)
#define D(k) (q[i]-q[(i+k)%12])
double q[12],r[12],s[4],p,n;

main(i){
F scanf("%lf",&q[i])
F r[i/3*3]+=D(3)*D(3),r[i/3*3+1]+=D(6)*D(6)
F r[i]=sqrt(r[i])
F i%3||(s[i/3]=r[(i+3)%12]/2),s[i/3]+=r[i]/2
F i%3||(p=s[i/3]-r[(i+3)%12]),p*=s[i/3]-r[i],n+=(i%3>1)*sqrt(p)
;printf("%lf",n);
}
``````