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个字符长度; ...
随机推荐
- 比Wireshark更轻量、更方便的抓包软件:Charles
转:http://blog.csdn.net/lixing333/article/details/42776187 之前写过一篇通过Wireshark进行抓包,分析网络连接的文章<通过WireS ...
- arcgis10.1安装出现1606错误怎么办?找不到盘符
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ESRIHKEY_LOCAL_MACHINE\SOFTWARE\ESRIHKEY_CURRENT_USER\Softwa ...
- String Matching(poj1580)
/*String Matching Description It's easy to tell if two words are identical - just check the letters. ...
- 微服务中的 API 网关(API Gateway)
API 网关(API Gateway)提供高性能.高可用的 API 托管服务,帮助用户对外开放其部署在 ECS.容器服务等云产品上的应用,提供完整的 API 发布.管理.维护生命周期管理.用户只需进行 ...
- Generalized normal distribution and Skew normal distribution
Density Function The Generalized Gaussian density has the following form: where (rho) is the " ...
- Django静态文件的加载以及STATIC_URL、 STATIC_ROOT 、STATICFILES_DIRS的区别
Djangon生产环境静态资源的处理 Django 关闭DEBUG模式后,就相当于是生产环境了. Django框架一旦作为生产环境,它的静态文件访问接口就不应该从Django框架中走,必须在Djang ...
- 【ContestHunter】【弱省胡策】【Round0】(A)&【Round1】(B)
DP+容斥原理or补集转化?/KD-Tree 唔……突然发现最早打的两场(打的最烂的两场)没有写记录……(太烂所以不忍记录了吗... 还是把搞出来了的两道题记录一下吧= =勉强算弥补一下缺憾…… Ro ...
- 同步一个 fork
fork 了别人的仓库后,原作者又更新了仓库,如何将自己的代码和原仓库保持一致?本文将给你解答. 如何使用搜索引擎 其实这个问题并不难,我又被坑了.百度搜的东西不靠谱啊,以后这种问题一定要用英文在 G ...
- 访问Oracle数据库的工具【unfinished】
ylbtech-Oracle:访问Oracle数据库的工具 访问Oracle数据库的工具 1. SQL*PLUS返回顶部 1.0, 1.0.1, 之network\admin\tnsnames.ora ...
- SQL Server 2005 分区表实践——分区切换
本文演示了 SQL Server 2005 分区表分区切换的三种形式: 1. 切换分区表的一个分区到普通数据表中:Partition to Table: 2. 切换普通表数据到分区表的一个分区中:Ta ...