3D玩法最优算法

  private string[] big ={ "5", "6", "7", "8", "9" };//大
        private string[] small ={ "0", "1", "2", "3", "4" };//小
        private string[] primeNumber ={ "1", "2", "3", "5", "7" };//质数
        private string[] heshu ={ "0", "4", "6", "8", "9" };//合数
        private string[] oddNnumber ={ "1", "3", "5", "7", "9" };//奇数
        private string[] even ={ "0", "2", "4", "6", "8" };//偶数
        private string[] all ={ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; //全      
  /// <summary>
        /// 复式算法(无重复算法)
        /// 适用一下类型:3A型(即A+A+A型)、定胆定位B型、大小类型、奇偶类型、质合类型
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <param name="third"></param>
        /// <returns></returns>
        public void get3AChoose(string[] first, string[] second, string[] third)
        {
            string[] compound = new string[first.Length * second.Length * third.Length];
            int count = 0;
            for (int i = 0; i < first.Length; i++)
            {
                for (int j = 0; j < second.Length; j++)
                {
                    for (int k = 0; k < third.Length; k++)
                    {
                        compound[count] = first[i] + second[j] + third[k];
                        count = count + 1;
                    }
                }
            }
            // return compound;
            quickSort(compound, 0, compound.Length - 1);
            for (int i = 0; i < compound.Length; i++)
            {
                System.Console.Write(compound[i] + ",");
                if ((i + 1) % 10 == 0) System.Console.Write("/n");
            }
        }
        /// <summary>
        /// 1D变3D型 定胆不定位A型
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public void oneTothreeA(string number)
        {
            int count = 0, selectNo;
            selectNo = Convert.ToInt32(number);
            string[] result = new string[271];
            for (int i = 0; i < 10; i++)
            {
                if (i == selectNo)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        if (k == i) continue;
                        result[count++] = number + i.ToString() + k.ToString();
                    }
                }
                else
                {
                    for (int j = 0; j < 10; j++)
                    {
                        result[count++] = number + i.ToString() + j.ToString();
                        result[count++] = i.ToString() + number + j.ToString();
                        if (j != Int32.Parse(number))
                            result[count++] = i.ToString() + j.ToString() + number;
                    }
                }
            }
            result[count] = number + number + number;
            quickSort(result, 0, count);
            // return result;
            for (int i = 0; i < result.Length; i++)
            {
                System.Console.Write(result[i] + ",");
                if ((i + 1) % 10 == 0) System.Console.Write("/n");
            }
        }

        /// <summary>
        /// 组3全包
        /// </summary>
        private void teamThreeAll()
        {
            string[] team = new string[90];
            int count = 0;
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (i == j) continue;
       team[count++] = i.ToString() + i.ToString() + j.ToString();                   
                }// end for
            }// end for           
            for (int i = 0; i < 90; i++)
            {
                System.Console.Write(team[i] + ",");
                if ((i + 1) % 10 == 0) System.Console.Write("/n");
            }
        }
   /// <summary>
        /// 组6全包
        /// </summary>
        /// <returns></returns>
        public void teamSixAll()
        {
            string[] team = new string[120];
            int count = 0;
            for (int i = 0; i < 8; i++)
            {
                for (int j = i+1; j < 9; j++)
                {
                    for (int k = j + 1; k < 10; k++)
                    {
                        team[count++] = i.ToString() + j.ToString() + k.ToString();
                    }
                   
                }// end for
            }// end for           
            for (int i = 0; i < 120; i++)
            {
                System.Console.Write(team[i] + ",");
                if ((i + 1) % 10 == 0) System.Console.Write("/n");
            }           
        }
        /// <summary>
        /// 和值
        /// </summary>
        /// <param name="d"></param>
        private void getsumValue(string d)
        {
            string[] number = new string[75];
            int sumValue = Int32.Parse(d);
            int count = 0;
            for (int a = 0; a < 10 && a <= sumValue; a++)
            {
                if (sumValue - a > 18) a = sumValue - 18;
                int b = 0, c = 0;
                if (sumValue - a - 9 > b) b = sumValue - a - 9;
                for (; b < 10 && b <= (sumValue - a); b++)
                {
                    c = sumValue - a - b;
                    number[count++] = a.ToString() + b.ToString() + c.ToString();
                    System.Console.Write(number[count - 1] + ",");
                    if (count % 10 == 0) System.Console.Write("/n");
                }
            }
            System.Console.WriteLine("和值为" + d + "的个数:" + count);

        }
        /// <summary>
        /// 和值
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public void sumValue(string number)
        {
            if (Int32.Parse(number) > 27 || Int32.Parse(number) < 0) return;
            string[] result = null;
            switch (Convert.ToInt32(number))
            {
                case 0: string[] result0 ={ "000" }; result = result0; break;
                case 1: string[] result1 ={ "001", "010", "100" }; result = result1; break;
                case 2: string[] result2 ={ "002", "011", "020", "101", "110", "200" }; result = result2; break;
                case 3: string[] result3 ={ "003", "012", "021", "030", "102", "111", "120", "201", "210", "300" }; result = result3; break;
                case 4: string[] result4 ={ "004", "013", "022", "031", "040", "103", "112", "121", "130", "202", "211", "220", "301", "310", "400" }; result = result4; break;
                case 5: string[] result5 ={ "005", "014", "023", "032", "041", "050", "104", "113", "122", "131", "140", "203", "212", "221", "230", "302", "311", "320", "401", "410", "500" }; result = result5; break;
                case 6: string[] result6 ={ "006", "015", "024", "033", "042", "051", "060", "105", "114", "123", "132", "141", "150", "204", "213", "222", "231", "240", "303", "312", "321", "330", "402", "411", "420", "501", "510", "600" }; result = result6; break;
                case 7: string[] result7 ={ "007", "016", "025", "034", "043", "052", "061", "070", "106", "115", "124", "133", "142", "151", "160", "205", "214", "223", "232", "241", "250", "304", "313", "322", "331", "340", "403", "412", "421", "430", "502", "511", "520", "601", "610", "700" }; result = result7; break;
                case 8: string[] result8 ={ "008", "017", "026", "035", "044", "053", "062", "071", "080", "107", "116", "125", "134", "143", "152", "161", "170", "206", "215", "224", "233", "242", "251", "260", "305", "314", "323", "332", "341", "350", "404", "413", "422", "431", "440", "503", "512", "521", "530", "602", "611", "620", "701", "710", "800" }; result = result8; break;
                case 9: string[] result9 ={ "009", "018", "027", "036", "045", "054", "063", "072", "081", "090", "108", "117", "126", "135", "144", "153", "162", "171", "180", "207", "216", "225", "234", "243", "252", "261", "270", "306", "315", "324", "333", "342", "351", "360", "405", "414", "423", "432", "441", "450", "504", "513", "522", "531", "540", "603", "612", "621", "630", "702", "711", "720", "801", "810", "900" }; result = result9; break;
                case 10: string[] result10 ={ "019", "028", "037", "046", "055", "064", "073", "082", "091", "109", "118", "127", "136", "145", "154", "163", "172", "181", "190", "208", "217", "226", "235", "244", "253", "262", "271", "280", "307", "316", "325", "334", "343", "352", "361", "370", "406", "415", "424", "433", "442", "451", "460", "505", "514", "523", "532", "541", "550", "604", "613", "622", "631", "640", "703", "712", "721", "730", "802", "811", "820", "901", "910" }; result = result10; break;
                case 11: string[] result11 ={ "029", "038", "047", "056", "065", "074", "083", "092", "119", "128", "137", "146", "155", "164", "173", "182", "191", "209", "218", "227", "236", "245", "254", "263", "272", "281", "290", "308", "317", "326", "335", "344", "353", "362", "371", "380", "407", "416", "425", "434", "443", "452", "461", "470", "506", "515", "524", "533", "542", "551", "560", "605", "614", "623", "632", "641", "650", "704", "713", "722", "731", "740", "803", "812", "821", "830", "902", "911", "920" }; result = result11; break;
                case 12: string[] result12 ={ "039", "048", "057", "066", "075", "084", "093", "129", "138", "147", "156", "165", "174", "183", "192", "219", "228", "237", "246", "255", "264", "273", "282", "291", "309", "318", "327", "336", "345", "354", "363", "372", "381", "390", "408", "417", "426", "435", "444", "453", "462", "471", "480", "507", "516", "525", "534", "543", "552", "561", "570", "606", "615", "624", "633", "642", "651", "660", "705", "714", "723", "732", "741", "750", "804", "813", "822", "831", "840", "903", "912", "921", "930" }; result = result12; break;
                case 13: string[] result13 ={ "049", "058", "067", "076", "085", "094", "139", "148", "157", "166", "175", "184", "193", "229", "238", "247", "256", "265", "274", "283", "292", "319", "328", "337", "346", "355", "364", "373", "382", "391", "409", "418", "427", "436", "445", "454", "463", "472", "481", "490", "508", "517", "526", "535", "544", "553", "562", "571", "580", "607", "616", "625", "634", "643", "652", "661", "670", "706", "715", "724", "733", "742", "751", "760", "805", "814", "823", "832", "841", "850", "904", "913", "922", "931", "940" }; result = result13; break;
                case 14: string[] result14 ={ "059", "068", "077", "086", "095", "149", "158", "167", "176", "185", "194", "239", "248", "257", "266", "275", "284", "293", "329", "338", "347", "356", "365", "374", "383", "392", "419", "428", "437", "446", "455", "464", "473", "482", "491", "509", "518", "527", "536", "545", "554", "563", "572", "581", "590", "608", "617", "626", "635", "644", "653", "662", "671", "680", "707", "716", "725", "734", "743", "752", "761", "770", "806", "815", "824", "833", "842", "851", "860", "905", "914", "923", "932", "941", "950" }; result = result14; break;
                case 15: string[] result15 ={ "069", "078", "087", "096", "159", "168", "177", "186", "195", "249", "258", "267", "276", "285", "294", "339", "348", "357", "366", "375", "384", "393", "429", "438", "447", "456", "465", "474", "483", "492", "519", "528", "537", "546", "555", "564", "573", "582", "591", "609", "618", "627", "636", "645", "654", "663", "672", "681", "690", "708", "717", "726", "735", "744", "753", "762", "771", "780", "807", "816", "825", "834", "843", "852", "861", "870", "906", "915", "924", "933", "942", "951", "960" }; result = result15; break;
                case 16: string[] result16 ={ "079", "088", "097", "169", "178", "187", "196", "259", "268", "277", "286", "295", "349", "358", "367", "376", "385", "394", "439", "448", "457", "466", "475", "484", "493", "529", "538", "547", "556", "565", "574", "583", "592", "619", "628", "637", "646", "655", "664", "673", "682", "691", "709", "718", "727", "736", "745", "754", "763", "772", "781", "790", "808", "817", "826", "835", "844", "853", "862", "871", "880", "907", "916", "925", "934", "943", "952", "961", "970" }; result = result16; break;
                case 17: string[] result17 ={ "089", "098", "179", "188", "197", "269", "278", "287", "296", "359", "368", "377", "386", "395", "449", "458", "467", "476", "485", "494", "539", "548", "557", "566", "575", "584", "593", "629", "638", "647", "656", "665", "674", "683", "692", "719", "728", "737", "746", "755", "764", "773", "782", "791", "809", "818", "827", "836", "845", "854", "863", "872", "881", "890", "908", "917", "926", "935", "944", "953", "962", "971", "980" }; result = result17; break;
                case 18: string[] result18 ={ "099", "189", "198", "279", "288", "297", "369", "378", "387", "396", "459", "468", "477", "486", "495", "549", "558", "567", "576", "585", "594", "639", "648", "657", "666", "675", "684", "693", "729", "738", "747", "756", "765", "774", "783", "792", "819", "828", "837", "846", "855", "864", "873", "882", "891", "909", "918", "927", "936", "945", "954", "963", "972", "981", "990" }; result = result18; break;
                case 19: string[] result19 ={ "199", "289", "298", "379", "388", "397", "469", "478", "487", "496", "559", "568", "577", "586", "595", "649", "658", "667", "676", "685", "694", "739", "748", "757", "766", "775", "784", "793", "829", "838", "847", "856", "865", "874", "883", "892", "919", "928", "937", "946", "955", "964", "973", "982", "991" }; result = result19; break;
                case 20: string[] result20 ={ "299", "389", "398", "479", "488", "497", "569", "578", "587", "596", "659", "668", "677", "686", "695", "749", "758", "767", "776", "785", "794", "839", "848", "857", "866", "875", "884", "893", "929", "938", "947", "956", "965", "974", "983", "992" }; result = result20; break;
                case 21: string[] result21 ={ "399", "489", "498", "579", "588", "597", "669", "678", "687", "696", "759", "768", "777", "786", "795", "849", "858", "867", "876", "885", "894", "939", "948", "957", "966", "975", "984", "993" }; result = result21; break;
                case 22: string[] result22 ={ "499", "589", "598", "679", "688", "697", "769", "778", "787", "796", "859", "868", "877", "886", "895", "949", "958", "967", "976", "985", "994" }; result = result22; break;
                case 23: string[] result23 ={ "599", "689", "698", "779", "788", "797", "869", "878", "887", "896", "959", "968", "977", "986", "995" }; result = result23; break;
                case 24: string[] result24 ={ "699", "789", "798", "879", "888", "897", "969", "978", "987", "996" }; result = result24; break;
                case 25: string[] result25 ={ "799", "889", "898", "979", "988", "997" }; result = result25; break;
                case 26: string[] result26 ={ "899", "989", "998" }; result = result26; break;
                case 27: string[] result27 ={ "999" }; result = result27; break;
            }
            for (int i = 0; i < result.Length; i++)
            {
                System.Console.Write(result[i] + ",");
                if ((i + 1) % 10 == 0) System.Console.Write("/n");
            }
        }
        /// <summary>
        /// 定两胆不定位 参数d1,d2分别为两胆
        /// </summary>
        /// <param name="d1"></param>
        /// <param name="d2"></param>
        private void getsurely2D(string d1, string d2)
        {
            string[] number = new string[54];
            int count = 0;
            if (d1.Equals(d2))
            {
                for (int i = 0; i < 10; i++)
                {
                    if (i.ToString().Equals(d1)) continue;
                    number[count++] = i.ToString() + d1 + d2;
                    number[count++] = d1 + i.ToString() + d2;
                    number[count++] = d1 + d2 + i.ToString();
                }
            }
            else
            {
                for (int i = 0; i < 10; i++)
                {
                    if (i.ToString().Equals(d1) || i.ToString().Equals(d2)) continue;
                    number[count++] = i.ToString() + d1 + d2;
                    number[count++] = d1 + i.ToString() + d2;
                    number[count++] = d1 + d2 + i.ToString();
                    number[count++] = i.ToString() + d2 + d1;
                    number[count++] = d2 + i.ToString() + d1;
                    number[count++] = d2 + d1 + i.ToString();
                }
                number[count++] = d1 + d1 + d2;
                number[count++] = d1 + d2 + d1;
                number[count++] = d2 + d1 + d1;
                number[count++] = d2 + d2 + d1;
                number[count++] = d2 + d1 + d2;
                number[count++] = d1 + d2 + d2;
            }
            for (int i = 0; i < 54; i++)
            {
                System.Console.Write(number[i] + ",");
                if ((i + 1) % 10 == 0) System.Console.Write("/n");
            }
        }
        /// <summary>
        /// 跨度型
        /// </summary>
        /// <param name="number"></param>
        public void spanValue(string number)
        {
            int span = Int32.Parse(number);
            string[] result = new string[150];
            int count = 0;
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        if (Math.Abs(i - j) == span && Math.Abs(i - k) <= span && Math.Abs(k - j) <= span)
                        {
                            result[count++] = i.ToString() + j.ToString() + k.ToString();
                        }
                        else if (Math.Abs(i - k) == span && Math.Abs(i - j) <= span && Math.Abs(k - j) <= span)
                        {
                            result[count++] = i.ToString() + j.ToString() + k.ToString();
                        }
                        else if (Math.Abs(k - j) == span && Math.Abs(i - k) <= span && Math.Abs(i - j) <= span)
                        {
                            result[count++] = i.ToString() + j.ToString() + k.ToString();
                        }
                    }
                }
            }
            for (int i = 0; i < count; i++)
            {
                System.Console.Write(result[i] + ",");
                if ((i + 1) % 10 == 0) System.Console.Write("/n");
            }
            System.Console.WriteLine("跨度值为:" + number + "组合个数为:" + count);
        }
        /// <summary>
        /// 快速排序法
        /// </summary>
        /// <param name="a"></param>
        /// <param name="low"></param>
        /// <param name="high"></param>
        public void quickSort(string[] a, int low, int high)
        {// 排序a [ low : high ], a[high+1] 有大值 

            if (low >= high) return;

            int i = low, // 从左至右的游标 

            j = high + 1; // 从右到左的游标 

            string pivot = a[low];

            // 把左侧>= pivot的元素与右侧<= pivot 的元素进行交换 

            while (true)
            {

                do
                {// 在左侧寻找>= pivot 的元素 

                    i = i + 1;

                } while ((a[i].CompareTo(pivot) < 0) && (i < high));

                do
                {// 在右侧寻找<= pivot 的元素 

                    j = j - 1;

                } while (a[j].CompareTo(pivot) > 0);

                if (i >= j) break; // 未发现交换对象 

                //交换a[i]和a[j]值
                string temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }

            // 设置p i v o t 

            a[low] = a[j];

            a[j] = pivot;

            quickSort(a, low, j - 1); // 对左段排序 

            quickSort(a, j + 1, high); // 对右段排序 

        }
        /// <summary>
        /// 去掉重复数据
        /// </summary>
        /// <param name="lottery"></param>
        /// <returns></returns>
        public string[] delrepetition(string[] lottery)
        {
            quickSort(lottery, 0, lottery.Length - 1);
            string[] temp = new string[lottery.Length];
            temp[0] = lottery[0];
            int count = 0;
            for (int i = 1; i < lottery.Length; i++)
            {
                if (temp[count - 1] != lottery[i])
                {
                    temp[count] = lottery[i];
                    count = count + 1;
                }
            }
            string[] Welfare = new string[count];
            for (int i = 0; i < count; i++)
            {
                Welfare[i] = temp[i];
            }
            return Welfare;
        } 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值