有这样12个数x5, x6, x7, x8, x9, x11, x15, x16, x19, x30, x33, x38,x后面的是倍数,要求寻找1-100之间的数,使之与这些倍数相乘,到寻找的这些数的总和必须小于任何一个数乘以他的倍数.
比如说:找到12个数分别是:20,20,15,15,13,12,11,10,9,8,7,6,那么必须满足:
20+20+15+15+13+12+11+10+9+8+7+6<5*20 and
20+20+15+15+13+12+11+10+9+8+7+6<6*20 and
20+20+15+15+13+12+11+10+9+8+7+6<7*20 and
20+20+15+15+13+12+11+10+9+8+7+6<8*20 and
20+20+15+15+13+12+11+10+9+8+7+6<9*20 and
20+20+15+15+13+12+11+10+9+8+7+6<11*20 and
20+20+15+15+13+12+11+10+9+8+7+6<15*20 and
20+20+15+15+13+12+11+10+9+8+7+6<16*20 and
20+20+15+15+13+12+11+10+9+8+7+6<19*20 and
20+20+15+15+13+12+11+10+9+8+7+6<30*20 and
20+20+15+15+13+12+11+10+9+8+7+6<33*20 and
20+20+15+15+13+12+11+10+9+8+7+6<38*20 
我的代码如下:
Int64 x5, x6, x7, x8, x9, x11, x15, x16, x19, x30, x33, x38;
for(x38=1;x38<100;x38++)
{
Console.WriteLine("computing......x38={0}",x38);
for(x33=x38+1;x33<100;x33++)
{
for(x30=x33+1;x30<100;x30++)
{
for(x19=x30+1;x19<100;x19++)
{
for(x16=x19+1;x16<100;x16++)
{
for(x15=x16+1;x15<100;x15++)
{
for(x11=x15+1;x11<100;x11++)
{
for(x9=x11+1;x9<100;x9++)
{
for(x8=x9+1;x8<100;x8++)
{
for(x7=x8+1;x7<100;x7++)
{
for(x6=x7+1;x6<100;x6++)
{
for(x5=x6+1;x5<100;x5++)
{
if(x5*5< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue;
if(x6*6< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue;
if(x7*7< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue;
if(x8*8< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue; if(x9*9< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue;
if(x11*11< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue;
if(x15*15< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue;
if(x16*16< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue; if(x19*19< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue;
if(x30*30< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue;
if(x33*33< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue;
if(x38*38< (x5+ x6+ x7+ x8+ x9+ x11+ x15+ x16+ x19+ x30+ x33+ x38)) continue;
Console.WriteLine("success!\r\n");
Console.WriteLine("x5={0},x5={1},x5={2},x5={3},x5={4},x5={5},x5={6},x5={7},x5={8},x5={9},x5={10},x5={11}", x5, x6, x7, x8, x9, x11, x15, x16, x19, x30, x33, x38);
Console.ReadLine();
}
}
}
}
}
}
}
}
}
}
}
}
Console.WriteLine("Compute Complete!\r\n");
Console.ReadLine();
-----------------------------------------------------------------------------
上述代码运行起来循环太多,不知道何时能算完?

解决方案 »

  1.   

    20+20+15+15+13+12+11+10+9+8+7+6<5*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<6*20 不知所云,如果20+20+15+15+13+12+11+10+9+8+7+6小于5*20,难道他会大于等于6*20不成?
      

  2.   

    >20+20+15+15+13+12+11+10+9+8+7+6<5*20 and
    >20+20+15+15+13+12+11+10+9+8+7+6<6*20 >不知所云,如果20+20+15+15+13+12+11+10+9+8+7+6小于5*20,难道他会大于等于6*20不成?
    20只是我随意取例的数字,实际运算中并不知道是多少.
      

  3.   

    SORRY:有这样12个数x5, x6, x7, x8, x9, x11, x15, x16, x19, x30, x33, x38,x后面的是倍数,要求寻找1-100之间的数,使之与这些倍数相乘,到寻找的这些数的总和必须小于任何一个数乘以他的倍数.
    比如说:找到12个数分别是:20,18,15,14,13,12,11,10,9,8,7,6,那么必须满足:
    20+20+15+15+13+12+11+10+9+8+7+6<5*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<6*18 and
    20+20+15+15+13+12+11+10+9+8+7+6<7*15 and
    20+20+15+15+13+12+11+10+9+8+7+6<8*14 and
    20+20+15+15+13+12+11+10+9+8+7+6<9*13 and
    20+20+15+15+13+12+11+10+9+8+7+6<11*12 and
    20+20+15+15+13+12+11+10+9+8+7+6<15*11 and
    20+20+15+15+13+12+11+10+9+8+7+6<16*10 and
    20+20+15+15+13+12+11+10+9+8+7+6<19*9 and
    20+20+15+15+13+12+11+10+9+8+7+6<30*8 and
    20+20+15+15+13+12+11+10+9+8+7+6<33*7 and
    20+20+15+15+13+12+11+10+9+8+7+6<38*6
      

  4.   

    20+20+15+15+13+12+11+10+9+8+7+6<5*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<6*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<7*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<8*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<9*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<11*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<15*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<16*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<19*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<30*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<33*20 and
    20+20+15+15+13+12+11+10+9+8+7+6<38*20 
    你只比较第一个不就行乐?第一个满足,后面的肯定满足阿