7-11便利店问题
小敏在7-11便利店买东西,挑了四件货物去收银台结账。正好收银机坏了,收银员小姐用计算器算账,得出\$7.11。小敏注意到收银员是把四个价格乘起来了,所以就提醒她算错了。收银员小姐重新算,把四个价格加起来,结果还是\$7.11。假定没有购物税。问:这四样东西的价格分别是多少? 本帖最后由 风云剑 于 2019-4-14 21:21 编辑for a in range(1, 711, 1):
for b in range(a, 711, 1):
for c in range(b, 711, 1):
d = 711 - a - b - c;
if(d >= c):
if(a * b * c * d == 711000000):
print(a, b, c, d);
风云剑 发表于 2019-4-14 21:20
if(d >= c) and (a * b * c * d == 711000000)::lol 风云剑 发表于 2019-4-14 21:20
py写的不优雅 print(a/100, b/100, c/100, d/100); 风云剑 发表于 2019-4-14 21:20
for b in range(a, 712)::lol {a,b,c,d}/100//{Plus@@#,Times@@#}&//({#//Factor,Round}//(PolynomialGCD@@#)^-1 #&//Last)&/@#&//{Prepend[#,{0}]}&//Nest[(Function[{u},Select]],#<=u[]/2\#<=Sqrt]]\#>=u[]&]//{Append],#],u[]-#,u[]/#}&/@#&]/@#//Join@@#&//Union)&,#,3]&//Select[#,#[]==#[]&]&//(Append[#[],#[]])&/@#&//Union//N[#/100]& 很广告的题目,是巧合么,所以搜索了一段距离。
ParallelTable[{4,{Plus,Times},i}//Function[{n,r,d},Array&,n]/100//Function[{xList},#@@xList&/@r]//({#,Round}//Factor//(PolynomialGCD@@#)^-1 #&//Last)&/@#&//{Prepend[#,{0}]}&//Nest[(Function[{u},Select]],#<=u[]/2\#<=Sqrt]]\#>=u[]&]//{Append],#],u[]-#,u[]/#}&/@#&]/@#//Join@@#&//Union)&,#,n-1]&//Select[#,#[]==#[]&]&//(Append[#[],#[]])&/@#&//Union//N[#/100]&]@@#&//{i,Length[#],#}&,{i,5,10,0.01}]//Select[#,#[]>0&]&
原来类似的结果其实蛮多的。
{{6.44,1,{{1.25,1.6,1.75,1.84}}},
{6.51,1,{{1.25,1.4,1.86,2.}}},
{6.6,1,{{1.1,1.5,2.,2.}}},
{6.63,1,{{1.25,1.25,1.92,2.21}}},
{6.65,1,{{1.,1.75,1.9,2.}}},
{6.72,1,{{1.12,1.5,1.6,2.5}}},
{6.75,2,{{1.,1.5,2.,2.25},{1.2,1.25,1.8,2.5}}},
{6.78,1,{{1.13,1.25,2.,2.4}}},
{6.8,1,{{1.,1.6,1.7,2.5}}},
{6.84,2,{{1.,1.44,1.9,2.5},{1.14,1.2,2.,2.5}}},
{6.86,1,{{1.,1.4,1.96,2.5}}},
{6.89,1,{{1.06,1.25,2.08,2.5}}},
{6.93,2,{{0.88,1.75,1.8,2.5},{1.,1.5,1.68,2.75}}},
{7.02,1,{{1.17,1.25,1.6,3.}}},
{7.05,1,{{1.,1.2,2.35,2.5}}},
{7.07,2,{{0.8,1.75,2.02,2.5},{1.,1.25,2.02,2.8}}},
{7.08,1,{{1.,1.18,2.4,2.5}}},
{7.11,1,{{1.2,1.25,1.5,3.16}}},
{7.13,1,{{1.,1.15,2.48,2.5}}},
{7.14,2,{{1.02,1.12,2.5,2.5},{1.19,1.25,1.5,3.2}}},
{7.2,3,{{0.8,1.5,2.4,2.5},{1.,1.2,2.,3.},{1.,1.5,1.5,3.2}}},
{7.25,1,{{0.8,1.45,2.5,2.5}}},
{7.26,1,{{0.75,1.76,2.,2.75}}},
{7.28,2,{{0.7,2.,2.08,2.5},{1.,1.28,1.75,3.25}}},
{7.29,1,{{1.,1.25,1.8,3.24}}},
{7.35,3,{{0.7,1.75,2.4,2.5},{1.,1.05,2.5,2.8},{1.2,1.25,1.4,3.5}}},
{7.37,1,{{0.67,2.,2.2,2.5}}},
{7.47,1,{{0.9,1.25,2.,3.32}}},
{7.5,1,{{1.,1.,2.5,3.}}},
{7.52,1,{{0.64,1.88,2.5,2.5}}},
{7.56,4,{{0.8,1.26,2.5,3.},{0.96,1.25,1.75,3.6},{1.12,1.25,1.44,3.75},{1.25,1.25,1.28,3.78}}},
{7.62,1,{{1.,1.27,1.6,3.75}}},
{7.65,4,{{0.6,2.,2.5,2.55},{0.75,1.5,2.,3.4},{1.,1.,2.25,3.4},{1.,1.2,1.7,3.75}}},
{7.67,1,{{0.59,2.08,2.5,2.5}}},
{7.7,2,{{1.,1.,2.2,3.5},{1.,1.25,1.6,3.85}}},
{7.74,3,{{0.75,1.29,2.5,3.2},{0.8,1.25,2.25,3.44},{1.2,1.25,1.29,4.}}},
{7.77,1,{{0.8,1.25,2.22,3.5}}},
{7.79,1,{{0.76,1.25,2.5,3.28}}},
{7.8,2,{{0.75,1.25,2.6,3.2},{1.,1.3,1.5,4.}}},
{7.82,1,{{0.92,1.,2.5,3.4}}},
{7.83,1,{{0.58,2.,2.25,3.}}},
{7.86,1,{{0.8,1.31,2.,3.75}}},
{7.92,3,{{0.72,1.25,2.75,3.2},{0.75,1.25,2.4,3.52},{0.9,1.,2.5,3.52}}},
{8.,1,{{1.,1.,2.,4.}}},
{8.01,1,{{0.75,1.2,2.5,3.56}}},
{8.03,1,{{0.88,1.,2.5,3.65}}},
{8.1,5,{{0.5,2.4,2.5,2.7},{0.6,1.5,3.,3.},{0.75,1.2,2.4,3.75},{0.75,1.35,2.,4.},{0.8,1.25,2.,4.05}}},
{8.12,1,{{0.5,2.32,2.5,2.8}}},
{8.16,1,{{0.85,1.,2.56,3.75}}},
{8.19,2,{{0.84,1.,2.6,3.75},{1.04,1.25,1.4,4.5}}},
{8.22,1,{{0.48,2.5,2.5,2.74}}},
{8.25,1,{{0.5,2.,2.75,3.}}},
{8.28,3,{{0.48,2.3,2.5,3.},{0.6,1.5,2.5,3.68},{0.69,1.25,2.5,3.84}}},
{8.33,3,{{0.7,1.25,2.38,4.},{0.85,0.98,2.5,4.},{0.85,1.25,1.75,4.48}}},
{8.36,1,{{0.76,1.1,2.5,4.}}},
{8.37,1,{{0.62,1.5,2.25,4.}}},
{8.4,2,{{0.5,2.,2.4,3.5},{0.7,1.2,2.5,4.}}},
{8.45,1,{{0.65,1.3,2.5,4.}}},
{8.46,2,{{0.64,1.25,2.82,3.75},{1.,1.25,1.41,4.8}}},
{8.52,1,{{0.6,1.42,2.5,4.}}},
{8.55,5,{{0.5,1.9,2.4,3.75},{0.5,2.,2.25,3.8},{0.75,1.,3.,3.8},{0.8,1.5,1.5,4.75},{1.,1.,1.8,4.75}}},
{8.6,1,{{0.8,1.,2.5,4.3}}},
{8.64,4,{{0.5,1.8,2.5,3.84},{0.54,1.6,2.5,4.},{0.64,1.5,2.,4.5},{1.,1.2,1.44,5.}}},
{8.67,1,{{0.5,1.7,2.72,3.75}}},
{8.69,1,{{0.79,1.,2.5,4.4}}},
{8.73,1,{{0.6,1.25,3.,3.88}}},
{8.75,2,{{0.5,1.75,2.5,4.},{1.,1.,1.75,5.}}},
{8.76,1,{{0.8,1.46,1.5,5.}}},
{8.78,1,{{0.64,1.25,2.5,4.39}}},
{8.82,5,{{0.42,2.4,2.5,3.5},{0.7,1.12,2.5,4.5},{0.75,1.25,1.92,4.9},{0.75,1.47,1.6,5.},{1.12,1.2,1.25,5.25}}},
{8.85,1,{{0.4,2.5,2.95,3.}}},
{8.88,1,{{0.75,1.28,1.85,5.}}},
{8.91,2,{{0.45,2.,2.5,3.96},{0.81,1.1,2.,5.}}},
{8.94,1,{{0.5,1.49,3.2,3.75}}},
{8.96,1,{{0.4,2.5,2.56,3.5}}},
{9.,3,{{0.4,2.5,2.5,3.6},{0.5,1.5,3.,4.},{0.5,2.,2.,4.5}}},
{9.02,1,{{0.82,1.,2.2,5.}}},
{9.03,2,{{0.43,2.1,2.5,4.},{0.48,1.75,2.5,4.3}}},
{9.12,1,{{0.6,1.52,2.,5.}}},
{9.18,2,{{0.48,1.7,2.5,4.5},{0.68,1.,3.,4.5}}},
{9.2,2,{{0.4,2.3,2.5,4.},{0.5,1.6,2.5,4.6}}},
{9.23,1,{{1.,1.25,1.3,5.68}}},
{9.24,1,{{0.64,1.,3.75,3.85}}},
{9.27,1,{{0.4,2.25,2.5,4.12}}},
{9.35,2,{{0.4,2.2,2.5,4.25},{0.85,1.,2.,5.5}}},
{9.36,3,{{0.5,1.56,2.5,4.8},{0.52,1.25,3.75,3.84},{0.65,0.96,3.75,4.}}},
{9.38,1,{{0.7,1.,2.68,5.}}},
{9.45,5,{{0.35,2.5,3.,3.6},{0.4,1.8,3.5,3.75},{0.45,1.5,3.5,4.},{0.75,0.9,2.8,5.},{0.8,0.9,2.5,5.25}}},
{9.48,2,{{0.5,1.28,3.75,3.95},{0.5,1.58,2.4,5.}}},
{9.54,1,{{0.75,0.8,3.75,4.24}}},
{9.57,1,{{0.75,1.,2.32,5.5}}},
{9.59,1,{{0.35,2.5,2.74,4.}}},
{9.6,3,{{0.6,1.,4.,4.},{0.8,0.8,3.,5.},{1.,1.,1.6,6.}}},
{9.62,1,{{0.37,2.,3.25,4.}}},
{9.63,2,{{0.5,1.25,3.6,4.28},{0.6,1.,3.75,4.28}}},
{9.66,2,{{0.5,1.4,2.76,5.},{0.8,1.25,1.61,6.}}},
{9.68,1,{{0.8,0.88,2.5,5.5}}},
{9.69,2,{{0.34,2.5,2.85,4.},{0.4,2.04,2.5,4.75}}},
{9.72,1,{{0.72,1.5,1.5,6.}}},
{9.75,1,{{1.,1.2,1.3,6.25}}},
{9.78,1,{{0.4,1.63,3.75,4.}}},
{9.8,2,{{0.4,2.,2.5,4.9},{0.7,1.,2.5,5.6}}},
{9.81,1,{{0.5,1.2,3.75,4.36}}},
{9.86,2,{{0.8,1.36,1.45,6.25},{0.85,1.16,1.6,6.25}}},
{9.87,2,{{0.47,1.4,3.,5.},{0.94,1.,1.68,6.25}}},
{9.89,1,{{0.92,1.,1.72,6.25}}},
{9.9,5,{{0.5,1.25,3.2,4.95},{0.5,1.5,2.4,5.5},{0.6,1.,3.3,5.},{0.75,0.75,4.,4.4},{0.8,1.2,1.65,6.25}}},
{9.92,1,{{0.32,2.5,3.1,4.}}},
{9.99,4,{{0.5,1.44,2.5,5.55},{0.74,0.75,4.,4.5},{0.74,1.,2.25,6.},{0.74,1.2,1.8,6.25}}}} zeroieme 发表于 2019-4-15 15:47
这个是我欣赏的算法,简单优雅:b:
页:
[1]