构造最接近圆周率的数。

11 次查看(过去 30 天)
homawan
homawan 2022-11-19
回答: lehave 2022-11-19
0 ~ 9 十个数字,构造出最接近圆周率的那个数。10个数全部使用,且不能重复.
比如37869/12054,你会有更好的结果吗?

采纳的回答

lehave
lehave 2022-11-19
clear;
A=perms(0:9);   %0到9全排列
u1=A(:,1)==0;   
u2=A(:,6)==0;   
u=u1|u2;
A(u,:)=[];      %剔除首位为0的数
k1=A(:,1:5);
k2=A(:,6:10);
w=[1e4,1e3,1e2,1e1,1];
k1=bsxfun(@times,k1,w);
k2=bsxfun(@times,k2,w);   
k1=sum(k1,2);
k2=sum(k2,2);    %将全排列转化为单个的五位数
t=k1./k2;
f=abs(t-pi);     
[a,b]=min(f);    %找出最近将pi的数字的位置
I1=k1(b)
I2=k2(b)
% A(b,:)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 R Language 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!