如题,要求速度最快,算法最好。

解决方案 »

  1.   

    100万个6位随机数插入List,然后通过Linq求次数最小数
      

  2.   

    先设置,初值 min=0 和一个0-999999的hash然后该怎么样就怎么样,单线程也好,多线程也罢,直接查找hash表就是。顺序的hash表是直接定位的用不着你查,所以你啥时候生成完,啥时候就计算完了这东西其实用不着啥特别的算法
      

  3.   

    正常情况下,应该是0次啦,
    sqlserver,两张表
    t1, id, 初始化为(0-999999)
    t2, num, 随机生成6位数字select t1.id, isnull(t.count, 0) as count from t1
    left join (select num, count(*) as count from t2 group by num) t
        on t.num = t1.id
    order by t.count好了,按出现次数排序了兄弟难道是卖彩票的?
      

  4.   


    我写到数据库中,就简单啦。一个表,一个min就搞定了。
    nCount  sixnum
    1    676829
    2    312312
    我不写入数据库中呢?还有我不是卖彩票的,我是买彩票的。
      

  5.   

    bitmap 计数
    int[] bitmap = new int[1000000];
    foreach (int x in yourdata)
    {
        bitmap[x]++;
    }
    int result = bitmap.Select((x, i) => new { x, i }).OrderBy(x => x.x).First().i;
      

  6.   

    实践证明,单纯random100W个6位数只需0.04秒多一点
      

  7.   

    Stopwatch watch=new Stopwatch();
    watch.Start();
    watch.Stop();
    watch.Elapsed;
      

  8.   

    小弟再问各位大侠一个问题,0-9这写数字(0可以在前面),生成4位的不重复的组合,能有多少个?6位不重复的组合又有多少个?小弟不才,写了个最简单的代码,各位大师给点意见: private void button1_Click(object sender, EventArgs e)
            {
                Random r = new Random();
                Hashtable ht = new Hashtable();
                long maxNum = 1000;            for (long i = 0; i < maxNum; i++)
                {
                    string temp;
                    temp = "";
                    for (int j = 0; j < 6; j++)
                    {
                        temp += r.Next(0, 9).ToString();
                    }                string KV;
                    if (ht.ContainsKey(temp))
                    {
                        KV =  ht[temp].ToString().Substring(0, ht[temp].ToString().IndexOf('_'));
                        KV = (Convert.ToSByte(KV)+1).ToString()+"_" + temp;                    ht[temp] = KV;
                    }
                    else
                    {
                        KV = "1_"+temp;
                        ht.Add(temp, KV);
                    }
                }
                ArrayList arrList = new ArrayList(ht.Values);
                arrList.Sort();
                txtResults.Text =  arrList[0].ToString();            string rTemp = "";
                for (int i = 0; i < arrList.Count; i++)
                {
                    rTemp = rTemp + arrList[i].ToString()+'\n';            }
                rtxt1.Text = rTemp;
            }
      

  9.   

    O(n)几倍的。。什么linq ..list..我去。