首页 > 编程语言 > 详细

[C#]横竖都是4九宫格算法

时间:2016-01-28 10:59:31      阅读:142      评论:0      收藏:0      [点我收藏+]

群里的网友抛出了这样一道题
技术分享
我的算法:

        static void Main(string[] args)
        {
            /*
             *  a + b - 9 = 4
             *  +    -    -  
             *  c - d * e =4
             * /     *    -
             * f  + g - h=4
             * ||     ||    ||
             * 4     4    4 
             * */
            int flag = 50;
            for(int a=0;a<14; a++) //a
            {
                for (int b = 0; b <14; b++) //b
                {
                    //a+b-9=4 故 a+b=13
                    if ((a + b) == 13)
                    {
                        //9-e-h=4 故 e+h=5, e<6,h<6
                        for (int e = 0; e < 6; e++)  //e  
                        {
                            for (int h = 0; h < 6; h++)  //h
                            {
                                if ((e + h) == 5) 
                                {
                                    for (int c = 0; c < flag; c++) //c
                                    {
                                        //b-d*g=4,b[0-13] 故d*g<10,d,g<10
                                        for (int d = 0; d < 10; d++) //d     d*g<=9
                                        {
                                            for (int g = 0; g < 10; g++) //g
                                            {
                                                //考虑到f为被除数,故f>0,考虑整除c%f==0
                                                for (int f = 1; f < flag; f++) //f
                                                {
                                                    while ((c % f )== 0&&(c - d * e) == 4 && (f + g - h) == 4 && (a + c / f) == 4 && (b - d * g) == 4) 
                                                    {
                                                            Console.WriteLine("----------------------------------");
                                                            Console.Write("a:{0} ", a.ToString());
                                                            Console.Write("b:{0} ", b.ToString());
                                                            Console.Write("c:{0} ", c.ToString());
                                                            Console.Write("d:{0} ", d.ToString());
                                                            Console.Write("e:{0} ", e.ToString());
                                                            Console.Write("f:{0} ", f.ToString());
                                                            Console.Write("g:{0} ", g.ToString());
                                                            Console.WriteLine("h:{0} ", h.ToString());
                                                            Console.WriteLine("----------------------------------");
                                                            Console.ReadLine();
                                                    }                                                                                     
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

技术分享

[C#]横竖都是4九宫格算法

原文:http://blog.csdn.net/david_520042/article/details/50598977

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!