C# “贝格尔”编排法
protected void Page_Load(object sender, EventArgs e)
{
List<int[]> list = new List<int[]>();
List<int> teams = new List<int> { 1, 2, 3, 4, 5, 6, 7 };
int[] array = teams.ToArray();
//参赛队数数量
int initlen = array.Length;
//比赛轮次
int turns = initlen - 1;
//如果为奇数,用0补空
if (Convert.ToBoolean(initlen % 2))
{
teams.Add(0);
turns = initlen;
}
list.Add(teams.ToArray());
int max = teams[teams.Count - 1];
//间隔数,计算公式为(n-4)/2+1
int steps = initlen <= 4 ? 1 : (initlen - 4) / 2 + 1; List<int> parseList = teams;
int temp = 0;
for (int n = 0; n < turns; n++)
{
//移除空位
bool isMax = parseList[0] == max ? true : false;
parseList.RemoveAt(parseList[0] == max ? 0 : parseList.Count - 1);
int[] tempArray = parseList.ToArray();
int templen = tempArray.Length;
int tempLen = isMax ? steps + 2 : steps;
for (int i = 0; i < tempLen; i++)
{
//右位移
temp = tempArray[templen - 1];
for (int j = templen - 2; j >= 0; j--)
{
tempArray[j + 1] = tempArray[j];
}
tempArray[0] = temp;
}
//补空位
string tempString = isMax ?
string.Format("{0},{1}", string.Join(",", tempArray), max) :
string.Format("{0},{1}", max, string.Join(",", tempArray));
int[] parseArray = Array.ConvertAll<string, int>(tempString.Split(','), s => int.Parse(s));
parseList = new List<int>(parseArray);
list.Add(parseArray);
}
//分队
for (int i = 0; i < list.Count; i++)
{
Response.Write(string.Format("---------第{0}轮--------<br/>", i));
int[] ar = list[i];
int length = ar.Length / 2;
int[] left = new int[length], right = new int[length];
List<int> lll = new List<int>();
for (int j = 0; j < length; j++)
{
left[j] = ar[j];
right[j] = ar[j + length];
}
Array.Reverse(right);
for (int j = 0; j < left.Length; j++)
{
Response.Write(string.Format("{0},{1}<br/>", left[j], right[j]));
}
}
}
结果:
---------第0轮--------
1,0
2,7
3,6
4,5
---------第1轮--------
0,5
6,4
7,3
1,2
---------第2轮--------
2,0
3,1
4,7
5,6
---------第3轮--------
0,6
7,5
1,4
2,3
---------第4轮--------
3,0
4,2
5,1
6,7
---------第5轮--------
0,7
1,6
2,5
3,4
---------第6轮--------
4,0
5,3
6,2
7,1
---------第7轮--------
0,1
2,7
3,6
4,5
C# “贝格尔”编排法的更多相关文章
- 【C/C++】实现龙贝格算法
1. 复化梯形法公式以及递推化 复化梯形法是一种有效改善求积公式精度的方法.将[a,b]区间n等分,步长h = (b-a)/n,分点xk = a + kh.复化求积公式就是将这n等分的每一个小区间进行 ...
- 奥格尔巧妙kfifo
奥格尔巧妙kfifo Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csdn.net/chen19870707 Date:O ...
- 龙贝格算法 MATLAB实现
龙贝格算法主要是不断递推和加速,直到满足精度要求 递推: 加速: 得到T表: MATLAB代码: function I = Romberg(f, a, b, epsilon) I = 0; h = b ...
- Three.js 火焰效果实现艾尔登法环动态logo 🔥
声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 背景 <艾尔登法环>是最近比较火的一款游戏,观察可以发现它的 Log ...
- iOS的非常全的三方库,插件,大牛博客
转自: http://www.cnblogs.com/zyjzyj/p/6015625.html github排名:https://github.com/trending, github搜索:http ...
- 创业之前 ——Paul Graham 最新博文
原文:Paul Graham 译者:李智维 /LeanCloudproject师 2014年10月 (这篇文章是我在斯坦福大学举办的Sam Altman创业课堂上的嘉宾演讲稿.本意是写给大学生的,但当 ...
- Intel 英特尔
英特尔 英特尔 基本资料 公司名称:英特尔(集成电路公司) 外文名称:Intel Corporation(Integrated Electronics Corporation) 总部地 ...
- 这份书单,给那些想学Hadoop大数据、人工智能的人
一.简单科普类 (文末附下载链接) 1.<人工智能:李开复谈AI如何重塑个人.商业与社会的未来图谱2> 作者:李开复,王咏刚 推荐理由:文章写得一般,但李开复和王永刚老师总结的还可以,算国 ...
- 天气预报API(二):全球城市、景点代码列表(“旧编码”)
说明 2016-12-10 补充 (后来)偶然发现中国天气网已经有城市ID列表的网页...还发现城市编码有两种,暂且称中国天气网这些编码为旧标准"旧编码"的特征是 9个字符长度; ...
随机推荐
- C#编程(二十五)----------接口
接口 如果一个类派生自一个接口,声明这个类就会实现某些函数.并不是所有的面向对象的语言都支持接口. 例如,有一个接口:IDispoable,包含一个方法Dispose(),该方法又类实现,用于清理代码 ...
- 【docker】docker的简单状态监控
命令: docker stats 可以使用占位符,显示想要看的信息: docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{ ...
- 【python】python安装步骤
1.官网下载python 官网地址:https://www.python.org/getit/ 2.下载完成后点击安装 勾选Add python to PATH 是可以自己去配置环境变量的 注意:这里 ...
- oracle11g忘记sys密码
目 录 1 以管理员身份运行cmd窗口 2 启动sqlplus并敲入一系列命令 3 特别注意 1以管理员身份运行cmd窗口 我安装的是oracle11.2版本,sqlplus.exe所在目录是:I: ...
- Reflector_8.3.0.93_安装文件及破解工具
Reflector_8.3.0.93_安装文件及破解工具 下载地址:http://pan.baidu.com/s/1jGwsYYM 约 8.9MB
- CSS:如何学习 CSS?
马上该转战互联网领域了,在此总结一下 CSS 学习的思路. 理解 CSS 的基本语法. 理解盒子模型. 理解文档流和定位. 理解浮动和清除. 理解各种 CSS 样式. 目前发现的最好的资源是:http ...
- Fix "Drives are running out of free space" Error in SharePoint Health Analyzer
前言 最近帮助用户做健康检查,用户发现事件查看器(EventView)里面有很多错误,有一个就是"Drives are running out of free space",而且每 ...
- 傲骨贤妻第一季/全集The Good Wife迅雷下载
第一季 The Good Wife Season 1 (2009)看点:在经受丈夫Peter的背叛以及因此而带来的公众羞辱后,Alicia Florrick选择重新继续自己原来的事业,一名辩护律师,以 ...
- Eclipse启动时提示fail to create the Java Virtual Machine问题的解决办法
是eclipse.ini文件的问题,打开eclipse安装目录下的eclipse.ini文件: 将其中的256m改为128m,512m改为256m,1024m改为512m即可 修改后如下: -star ...
- 《OSPF和IS-IS详解》
<OSPF和IS-IS详解> 基本信息 作者: (美)Jeff Doyle 译者: 孙余强 出版社:人民邮电出版社 ISBN:9787115347886 上架时间:2014-4-25 出版 ...