搬砖问题(C语言编程)
发布网友
发布时间:2022-05-01 12:46
我来回答
共2个回答
热心网友
时间:2023-10-13 02:52
//穷举法,列举出每一种组合,从中找出符合条件的。
#include<stdio.h>
void main()
{
int men,women,kids,people,bricks;
for(men=0;men<10;men++)
for(women=0;women<13;women++)
for(kids=0;kids<37;kids=kids+2)
{
people=men+women+kids;
bricks=4*men+3*women+1*(kid/2);
if(people==36&&bricks==36)
printf("it needs %d men ,%d women and %d kids\r\n",men,women,kids);
}
}
热心网友
时间:2023-10-13 02:53
3男3女30个小孩
热心网友
时间:2023-10-13 02:52
//穷举法,列举出每一种组合,从中找出符合条件的。
#include<stdio.h>
void main()
{
int men,women,kids,people,bricks;
for(men=0;men<10;men++)
for(women=0;women<13;women++)
for(kids=0;kids<37;kids=kids+2)
{
people=men+women+kids;
bricks=4*men+3*women+1*(kid/2);
if(people==36&&bricks==36)
printf("it needs %d men ,%d women and %d kids\r\n",men,women,kids);
}
}
热心网友
时间:2023-10-13 02:53
3男3女30个小孩