五户共井问题

5户共井问题。有A、B、C、D、E5家人共用一口井,已知井深不超过10m。A、B、C、D、E的绳长各不相同,从井口放下绳索正好到达水面时:

a) 需要A家的绳2条接上B家的绳1条;
b) 需要B家的绳3条接上C家的绳1条;
c) 需要C家的绳4条接上D家的绳1条;
d) 需要D家的绳5条接上E家的绳1条;
e) 需要E家的绳6条接上A家的绳1条;
问井深和各家绳长。



#include
#include


void main ()
{
float depth;
float a,b,c,d,e;
bool flag = 1;
int num=10;
do
{
for (depth = num ;depth > 0;depth--)
{
for (a = 0; a < num ;a++)
{
for (b = 0; b < num;b++)
{
if(2*a+b!=depth) continue;
for (c = 0 ;c <num ;c++)
{
if(3*b+c != depth) continue;
for (d = 0; d<num ;d++)
{
if(4*c + d !=depth) continue;
for (e = 0; e< num ;e++)
{
if (5*d +e !=depth) continue;
if (6*e+a==depth)
{
cout <<"井深和A,B,C,D,E绳长分别是:\n";
cout << depth/num*10<<endl <<a/num*10<<endl <<b/num*10<<endl<<c/num*10<<endl<<d/num*10<<endl<<e/num*10<<endl;
flag = 0;
break;
}

}
}
}
}
}
}
if (flag)
{
num = num*10;
}
}
while(flag);

}

Related Articles

Quote Of The Day