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条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS7设置SWAP分区,小内存服务器的救世主
- Mario游戏-低调大师作品
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- 2048小游戏-低调大师作品
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS8安装Docker,最新的服务器搭配容器使用
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS7,CentOS8安装Elasticsearch6.8.6