日期:2014-05-20  浏览次数:21392 次

求教:计算重复率的公式或算法
有题目ID列表:a   b   c   d

每次随机抽取3道题目,共抽了5次:
第1次:b   a   c
第2次:c   b   d
第3次:d   b   a
第4次:c   a   d
第5次:b   d   a

统计:
a出现4次
b出现4次
c出现3次
d出现4次

求:计算重复率的公式或算法

------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Text;

namespace Creator
{
public class TestPaperCreator
{
public static void Main()
{
new TestPaperCreator().Create(5, 3);
}

/// <summary>
/// 出题
/// </summary>
/// <param name= "pageKind "> 出题的套数 </param>
/// <param name= "problemNumber "> 每套题的题目数 </param>
public void Create(int pageKind,int problemNumber)
{
ItemLib lib = new ItemLib();

//每套题目数不能大于题库的总数
if (problemNumber > lib.Items.Count)
return;

Random rd = new Random();

for (int i = 0; i < pageKind; i++)
{
Console.WriteLine( "------------------------------------------- "+i.ToString()+ "--Start-- ");
List <Item> tempLib = new List <Item> ();
tempLib.AddRange(lib.Items);

//出现次数增加那么被选中的概率就会减少
for (int j = 0; j < problemNumber; j++)
{
int sumTimes = 0;
foreach (Item item in tempLib)
{
sumTimes += item.Times;
}

//获得选择依据
int selectKey = rd.Next(sumTimes*(tempLib.Count-1));

int value = 0;
Item selectItem = null;
foreach(Item item in tempLib)
{
value += sumTimes - item.Times;
if (selectKey <= value)
{
selectItem = item;
break;
}
}

//次数加1
selectItem.Times++;
tempLib.Remove(selectItem);
Console.WriteLine( "title: " + selectItem.Name + " Content: " + selectItem.Content);
}

Console.WriteLine();
}


Console.WriteLine( "--------------------------------------------Summary-- ");
foreach (Item item in lib.Items)
{
int occurTimes = item.Times-1;
Console.WriteLine( "title: " + item.Name + " Occur Times: " + occurTimes.ToString());
}
}
}

/// <summary>
/// 题库
/// </summary>
public class ItemLib
{
private List <Item> m_Items = new List <Item> ();

public List <Item> Items
{
get { return m_Items; }
set { m_Items = value; }
}

public ItemLib()
{
//you can get data form library
m_Items.Add(new Item( "A ", "1+1=? "));