如题!这个怎么做?先谢谢大家了!
解决方案 »
- #########求好用的代码生成工具 xml to class#########
- 我想做一个下载系统,怎样做一个像迅雷那样,可以在用户已经下载过的URL,提示"该URL已经存在!"
- 不安装office 能用程序读取ACCESS 文件吗
- 子窗体中打开窗体
- RemotingObject对象中需要使用配置文件变量时怎么处理?
- 数据库恢复的问题~~~请大家帮忙啊!!急!!
- 非常需要帮助!!!!! 需 com组件“MicroSoft Word 9.0 Object Library” 的使用帮助,我总不能靠猜测来读 Word 文档吧 ..........
- 关于|与||的区别与应用
- 要做项目经理了,请问项目经理的职责(需要做什么工作),需要懂那些知识?希望有经验的项目经理回答!
- 那里有有关分布式计算和多层应用的C#的资料?
- xml内容读取的问题
- 如何控制TreeView的尺寸? asp.net
List<int> result = GetResult(2000, 10);
static List<int> GetResult(int sum, int count)
{
int[] array = Enumerable.Range(0, sum).ToArray();
List<int> result = new List<int>(count);
int remain;
while (true)
{
remain = sum;
while (result.Count < count - 1)
{
int avg = (remain / (count - result.Count));
//根据鸽笼原理,必须有一个值在范围
//avg + Environment.TickCount % (remain - avg)之内
int value = array[avg + Environment.TickCount % (remain - avg)];
result.Add(value);
remain -= value;
}
result.Add(sum - result.Sum()); //如果都不相同,表明取值成功,否则重新取值
if (result.Distinct().Count() == result.Count)
{
break;
}
else
{
result.Clear();
}
}
return result;
}
{
int sum = 100;
int count = 5;
int n = 0;
Random rd = new Random();
for (int i = 1; i <= count - 1; i++)
{
do
{
n = rd.Next(1,sum);
}
while (n > sum + i - count);
sum = sum - n;
Console.Write(n + " ");
}
Console.Write(sum);
Console.ReadKey();
}
from b in Enumerable.Range(a, n)
from c in Enumerable.Range(b, n)
where a + b + c < n
select new { A = a, B = b, C = c };
5个数为相邻2项的差,1,11,15,11,2
第一步:生成包含 n 个数的序列,其中每个数都是 sum/n,第二步:给“每一对”加上随机的偏移量,比如:
offset = rnd.next();
numbers[0] = numbers[0] + offset;
numbers[1] = numbers[1] - offset;第三步不是必须的,但是如果你追求好看,就把这个序列打乱,让它看起来像是随机的