Game competition (c + +)

Source: Internet
Author: User

Race competition
Difficulty level: A; run time limit: 1000ms; operating space limit: 256000KB; code length limit: 2000000B
Question Description
There are n=2^m players in your class who want to have a tennis round robin. A match schedule is now designed to meet the following requirements:
1. Each player must race with the other n-1 players.
2. Each contestant can only compete once a day.
3. The round robin ends within n-1 days.
Please follow this request to design the tournament schedule as a table with n rows and n columns, as shown in the form and contents of the table. Fill in the Form I and J of the table with the contestants encountered by the first player on J Day.
Input
Input m
Output
Table-type tournament schedule, each row of data 22 separated by a space
Input example
3
Output example
1 2 3 4 5 6 7 8
2 1 4 3 6 5 8 7
3 4 1 2 7 8 5 6
4 3 2 1 8 7 6 5
5 6 7 8 1 2 3 4
6 5 8 7 2 1 4 3
7 8 5 6 3 4 1 2
8 7 6 5 4 3 2 1

#include <iostream>
#include <cstdio>
using namespace Std;
int a[100][100];
void table (int k, int n)
{
for (int i=1; i <= N; i + +)
{
A[1][i] = i;
}
int m = 1;
for (int s = 1; s <= k; s++)
{
n/=2;
for (int t = 1; t <= N; t++)
for (int i = m+1; I <= 2*m; i++)
for (int j = m+1; J <= 2*m; j + +)
{
a[i][j+ (t-1) *m*2] = a[i-m][j+ (t-1) *m*2-m];
a[i][j+ (t-1) *m*2-m] = a[i-m][j+ (t-1) *m*2];
}
M *= 2;
}
}
int main ()
{
int k;
Cin >> K;

int n = 1;
for (int i = 1; I <= K; i++)
n *= 2;
Table (k, n);

for (int i = 1; I <= n; i + +)
{
for (int j = 1; J <= N; j + +)
{
printf ("%d%c", A[i][j], j!=n? ' ': ' \ n ');
}
}
}

Game competition (c + +)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.