15

球面多余的三角形

，在哪里

• 余弦定律：

• 罪法：

任务

``````90N0E
0N0E
0N90E
``````

``````89.999989
``````

``````90N
0N0E
0N90E
``````

``````89.999989
``````

``````0N0E
0N179E
90N0E
``````

``````178.998863
``````

``````10N10E
70N20W
70N40E
``````

``````11.969793
``````

计分

1

Level River St

@steveverrill更新了任务。一度的精度就足够了。
pawel.boczarski 2015年

@ pawel.boczarski纬度/经度是否总是整数？

@flawr是的，我更新了任务。
pawel.boczarski 2015年

4

Matlab，288 266字节

``````                                  %parsing the input
for k=1:3;
s=input('','s');              %request input
if sum(s>57)<2;               %if we have only one letter, add arbitrary second coordinate
s=[s,'0E'];
end;
S=1-2*(s(s>57)>80);           %calculate the sign of the coordinates
s(s>57)=44;                   %replace letters with comma
L(k,:)=eval(['[',s,']']).*S;  %evaluates string as list and multiply with signs
end;
i=[2,3,1];
%calculate the angular distance between each pair of points
a=arrayfun(@distance,L(:,1),L(:,2),L(i,1),L(i,2))*pi/180;
%evaluate the spherical excess
f=@(a,b,c)sum(acos((cos(a)-cos(b).*cos(c))./(sin(b).*sin(c))))-pi;
disp(f(a,a(i),a([3,1,2]))*180/pi)``````

``````for k=1:3;s=input('','s');if sum(s>57)<2;s=[s,'0E'];end;
s(s>57)=44;L(k,:)=eval([91,s,93]).*(1-2*(s(s<48)>80));end;
i=[2,3,1];p=pi/180;a=arrayfun(@distance,L(:,1),L(:,2),L(i,1),L(i,2))*p;
b=a(i);disp((sum(acos((cos(a([3,1,2]))-cos(b).*cos(a))./(sin(b).*sin(a))))-pi)/p)
``````

3

Ruby，修订版3264255字节

`r`定义新常数= 180 / PI，并在整个函数中使用。`e`必须将其初始化为+ PI，因此多余的费用现在开始递减并在返回之前取反。

`t[]`消除：Ruby允许将分配给的数据`t[]`直接分配给`u,v,w.`

``````include Math
->s{r=180/e=PI
x=y=z=n=[]
9.times{|i|i<6?(u,v,w=eval(?[+s[i%3].gsub(/[NE]/,"/r,").gsub(/[SW]/,"/-r,")+"0]")
i%2<1&&x=y=z=1
n[i/2]=(z*=sin(u))+(y*=cos(v)*w=cos(u))+x*=w*sin(v)):e-=acos((n[i-7]-(c=n[i-6])*d=n[i-8])/sqrt((1-c*c)*(1-d*d)))}
-e*r}
``````

红宝石，版本1 283 277个字节

``````include Math
->s{x=y=z=n=[]
6.times{|i|t=eval(?[+s[i%3].gsub(/[NE]/,k="*PI/180,").gsub(/[SW]/,"*-1"+k)+"0]")
i%2<1&&x=y=z=1
n[i/2]=(z*=sin(u=t[0]))+(y*=cos(u)*cos(v=t[1]))+(x*=cos(u)*sin(v))}
e=-PI
3.times{|i|e+=acos((n[i-1]-n[i]*d=n[i-2])/sqrt((1-n[i]**2)*(1-d**2)))}
e/PI*180}
``````

``````Example:  70N20W --> [70*PI/180,20*-1*PI/180,0]
``````

``````include Math
g=->s{
n=[]         #array for dot products
x=y=z=1      #it's required to use these variables once before the loop, for some bizarre reason
6.times{|i|
t=eval(?[+s[i%3].gsub(/[NE]/,k="*PI/180,").gsub(/[SW]/,"*-1"+k)+"0]")
i%2<1&&x=y=z=1
n[i/2]=(z*=sin(u=t[0]))+(y*=cos(u)*cos(v=t[1]))+(x*=cos(u)*sin(v))
}

e=-PI        #set e to -PI and begin accumulating angles
3.times{|i|
e+=acos((n[i-1]-n[i]*n[i-2])/sqrt((1-n[i]**2)*(1-n[i-2]**2)))
}

e/PI*180}      #return value

puts g[gets.split]
``````