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个字符长度; ...
随机推荐
- pthread_join与pthread_detach细节问题
http://www.360doc.com/content/13/0106/09/9171956_258497083.shtml pthread_t pthr; pthread_create(& ...
- 树莓派2B安装Xware迅雷远程下载
转自:http://www.cnblogs.com/liangjh/articles/5347811.html 一.安装使用迅雷Xware (1)下载Xware1.0.31_armel_v5te_gl ...
- Windows下LuaJIT的编译和使用
1.下载LuaJIT,download>> 2.编译 开始 –> 程序 –> Microsoft Visual Studio xx –> Visual Studio To ...
- Java_并发线程_Semaphore、CountDownLatch、CyclicBarrier、Exchanger
1.Semaphore 信号量(Semaphore),有时被称为信号灯,是在多线程环境下使用的一种设施, 它负责协调各个线程, 以保证它们可以正确.合理的使用公共资源. Semaphore当前在多线程 ...
- Eclipse with ADT的安装和使用
我们从安卓官方网站下载下来的eclipse是捆绑好了ADT的,所以不用自己安装插件. 我现在在这个目录下简历一个空的文件夹--virtual,用来来存放虚拟机. 然后,在我的电脑上右键->属性, ...
- .Net Excel操作之NPOI(一)简介
一.NPOI简介 NPOI是一个开源项目,可以读/写xls,doc,ppt文件,有着广泛的应用. 使用NPOI能够帮助开发者在没有安装微软Office的情况下读写Office 97-2003的文件,支 ...
- 深入理解多线程(五)—— Java虚拟机的锁优化技术
本文是<深入理解多线程>的第五篇文章,前面几篇文章中我们从synchronized的实现原理开始,一直介绍到了Monitor的实现原理. 前情提要 通过前面几篇文章,我们已经知道: 1.同 ...
- composer - No business network has been specified for this connection 解决方案
I have installed hyperledger composer locally. But on localhost it gives error : Error : Error tryin ...
- VMware vSphere中的HA工作原理介绍
http://blog.51cto.com/linkinsds/416738 HA全称High Availability.它是VMware的企业应用环境中用来保障企业级应用的不间断运行需求所产生的一个 ...
- idea 2018.1破解激活方法,有效期至2099年 idea 激活 破解
最近笔者测试了好多破解Idea的方法,最简单操作方法莫过于用license server激活,但是此类方法对最新的2017.3.2版已经无效了,亲测哦,如下图所示. 针对新版的IntelliJ ID ...