[Fortran] 纯文本查看 复制代码
program main
implicit none
real x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,f1,f2,f3,f4,f5,f6,f7,f8,a,m,b,c,i
integer x(1:6)
print*,'请输入x1,x2,x3,x4,x5,x6,b:'
read*,b
do i=1,6
read*,x(i)
f1=x1-x2+2.0*x1*x1+2.0*x1*x2+x2*x2
f2=x3-x4+2.0*x3*x3+2.0*x3*x4+x4*x4
f3=x5-x6+2.0*x5*x5+2.0*x5*x6+x6*x6
f4=max(f1,f2,f3)
if (f4==f1) then
x7=x1
x8=x2
x11=(x3+x5)/2.0
x12=(x4+x6)/2.0
else if (f4==f2)then
x7=x3
x8=x4
x11=(x1+x5)/2.0
x12=(x2+x6)/2.0
else
x7=x5
x8=x6
x11=(x3+x1)/2.0
x12=(x4+x2)/2.0
end if
f5=min(f1,f2,f3)
if (f5==f1) then
x9=x1
x10=x2
else if (f5==f2) then
x9=x3
x10=x4
else
x9=x5
x10=x6
end if
f6=x11-x12+2.0*x11*x12+2.0*x11*x11+x12*x12
x13=2.0*x11-x7
x14=2.0*x12-x8
f7=x13-x14+2.0*x13*x13+2.0*x13*x14+x14*x14
if (f7<f6) then
x15=2.0*x13-x11
x16=2.0*x14-x12
else
x15=0.5*x7+0.5*x11
x16=0.5*x8+0.5*x12
end if
f8=x15-x16+2.0*x15*x15+2.0*x15*x16+x16*x16
if (f8<f5) then
x1=x1
x2=x2
x3=x15
x4=x16
x5=x5
x6=x6
else
x1=x1
x2=x2
x3=x13
x4=x14
x5=x5
x6=x6
end if
if (f8>f5.and.f8<f4) then
x1=x1
x2=x2
x3=x3
x4=x4
x5=x15
x6=x16
end if
m=(f1-f6)**2/3.0+(f8-f6)**2/3.0+(f3-f6)**2/3.0
a=sqrt(m)
if (a<b) exit
end do
print*,a
end