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个字符长度; ...
随机推荐
- Javascript中的依赖注入
首先通过带参函数来定义一个Javascript函数,相当于C#中的一个类. var Person = function(firstname, lastname){ this.firstname = f ...
- 使用Axure RP原型设计实践01,使用概述
首先认识Axure RP Pro 7.0软件的默认界面布局.最上面的是工具栏区域,左侧上方的是网站地图区域(sitemap),左侧中部的是部件区域(Widgets),左侧下方的是模板区域(Master ...
- 在ASP.NET MVC中使用typeahead.js支持预先输入,即智能提示
使用typeahead.js可以实现预先输入,即智能提示,本篇在ASP.NET MVC下实现.实现效果如下: 首先是有关城市的模型. public class City { public int Id ...
- 标记 {x:Null},d:DesignWidth,d:DesignHeight
{x:Null}:用于设置某属性值为Null,比如<Rectangle Fill="{x:Null}" />,其实就相当于<Rectangle />,个人感 ...
- MyBatis-Generator最佳实践
引用地址:http://arccode.net/2015/02/07/MyBatis-Generator%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5/ 最近使用MyBati ...
- 清理tomcat服务器缓存
据悉,2014年最流行的应用服务器排行榜揭晓Tomcat仍然处于领先位置.41%的部署使用的是Tomcat,和2013年的43%的市场份额数据一 致.下面还是我们的热门选择Jetty和JBoss/Wi ...
- c++ #ifdef的用法
http://www.tuicool.com/articles/mIJnumB #ifdef的用法 灵活使用#ifdef指示符,我们可以区隔一些与特定头文件.程序库和其他文件版本有关的代码.代码举例: ...
- Charles抓包https
Charles抓包https 灰灰是只小贱狗 2018.05.08 10:46 字数 762 阅读 7800评论 3喜欢 3 抓取HTTPS请求包,对数据进行排查检验 1.安装Charles 2.电脑 ...
- iOS:仿写探探App动画
一.简单介绍 探探动画比较新颖,这也是它在众多交友软件中火热的一个特色.实现这种动画的方式可以有两种方式实现: 1.使用转场动画实现 2.使用CollectionView自定义布局实现, 此处我提供 ...
- C#高级编程六十六天----表达式树总结【转】
https://blog.csdn.net/shanyongxu/article/details/47257139 表达式树总结 基础 表达式树提供了一个将可执行代码转换成数据的方法.如果你要在执行代 ...