百马百石

         //大马驼2石粮食,中等马驼1石粮食,两头小马驼1石粮食,
            //要用100匹马,驼100石粮食,该如何分配?
            int count=0;
            for (int da = 0; da <= 50;da++ )
            {
                for (int zhong = 0; zhong <= 100;zhong++ )
                {
                    for (int xiao = 0; xiao <= 200;xiao++ )
                    {
                        if(da+zhong+xiao==100&&2*da+zhong+0.5*xiao==100)
                        {
                            count++;
                            Console.WriteLine("" + count + "种分配方法:大马:" + da + "匹,中等马:" + zhong + "匹,小马:" + xiao + "");
                        }
                    }
                }
            }
            Console.WriteLine("共有" + count + "种方法");
            Console.ReadLine();

 

posted @ 2016-05-04 21:57  枫炎  阅读(275)  评论(0编辑  收藏  举报