Console-算法[for]-穷举法:百钱买百鸡

ylbtech-Arithmetic:Console-算法[for]-穷举法:百钱买百鸡
 
1.A,案例
-- ========================================================
-- ylb:算法
-- Type:算法[for],穷举法
-- munu:-百钱买百鸡
-- 20:32 2012/3/16
-- ========================================================
1.B,解决方案
using System;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            /*******************************
             公鸡 4块钱  母鸡 2块钱  小鸡 5毛
             一百块钱 买 一百只鸡  
             ********************************/
            int g;  //公鸡数量
            int m;  //母鸡数量
            int x;  //小鸡数量
            for (g = 0; g <= 25; g++)
            {
                for (m = 0; m <= 50; m++)
                {
                    for (x = 0; x <= 200; x++)
                    {
                        if (g + m + x == 100 && g * 4 + m * 2 + x * 0.5 == 100)
                        {
                            Console.WriteLine("g={0},m={1},x={2}",g,m,x);
                        }
                    }
                }
            }
        }
    }
}
1.C,运行结果
g=1,m=31,x=68
g=4,m=24,x=72
g=7,m=17,x=76
g=10,m=10,x=80
g=13,m=3,x=84
请按任意键继续. . .
warn 作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
posted on 2013-02-21 23:34  ylbtech  阅读(506)  评论(0编辑  收藏  举报