题目:100匹马背100担粮。 大马一匹背3担,中马一匹背2担。小马2匹背一担。请编程输出所有满足条件的情况.
这道题目到底考什么呢?相对来说,确实简单,有点意外。
我的分析:
大马最多的情况下是20匹,中马最多不超过33匹。这只是数学不等式。
public class Text3G
{
public static void main(String[] args)
{
int i,j;//i代表大马,j代表中马
for(i=0;i<=20;i++)
for(j=0;j<=33;j++)
{
if((100-i-j)%2!=0)
continue;
if(3*i+2*j+(100-i-j)/2==100)
System.out.println("big horse is "+i+"middle horse is "+j+"small
horse is "+(100-i-j));
}
}
}