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
关注公众号
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
C#调用Windows(8/10)自带的虚拟键盘
原文: C#调用Windows(8/10)自带的虚拟键盘 以下是调用代码: private const Int32 WM_SYSCOMMAND = 274; private const UInt32 SC_CLOSE = 61536; [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern bool PostMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Au...
-
下一篇
C# WPF 滚动字幕实现
原文: C# WPF 滚动字幕实现 <Window x:Class="Micro.Crawler.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="数据采集器" Height="350" Width="525" Loaded="Window_Loaded"> <Grid> <Canvas VerticalAlignment="Top" Height="46" ClipToBounds="True" Margin="0,138,0,0"> <StackPanel Name="content1"> <StackPanel.RenderTransform> <TranslateTransform Y="0" /> </StackPanel.RenderTransform> <T...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- MySQL表碎片整理
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Crontab安装和使用
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- SpringBoot2全家桶,快速入门学习开发网站教程
- Docker安装Oracle12C,快速搭建Oracle学习环境

微信收款码
支付宝收款码