Blue Bridge: games played

Matchmaking

Problem Description
There has 2 n- ( n-<=. 6) into a team game ⾏ Robin ⽐ plans to completion within 2 n -1, each team games into ⾏ ⼀ ⽐ game day.
Design ⼀ a ⽐ tournament arrangements, each with different teams are on the watch ⽐ race in 2 n -1 days.
START input format
Entering text member matchplan.in co ⼀ ⾏, START n input values.
Output Format
Output files matchplan.out Total ( 2 n--1) ⾏, the i ⾏ outputs i day ⽐ race arrangements.
Format: <i> AB, CD, ....... Where i is the number of days, A , B are double race ⽐ ⽅ number for each ⾏ total 2 n-1 th track ⽐ times.
Sample lose START
2
Sample Output
<1>1-2,3-4
<2>1-3,2-4
<3>1-4,2-3
analysis:
1. The meaning of the questions, the team's first arrange number smaller size ⽐ first game, each team must race day ⽐
2. Each team back to pick the team ⽐ recent tournament, marked today ⽐ over the race, and marked a two team race ⽐ too ~
 
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
 int n, m, a[1000], mp[10000] = {0};
 cin >> n;
 m = pow(2, n);
 for( int i = 1; i <= m - 1; i++) {
      memset(a, 0, sizeof(a));
 printf("<%d>", i);
 for ( int j = 1; j <= m; j++) {
       if ( a[j] == 0) {
            for ( int k = j + 1; k <= m; k++) {
                  if ( mp[j * 100 + k] == 0 && a[k] == 0) {
                       printf("%d-%d ", j, k);
                       mp[j * 100 + k] = 1;
                       a[j] = a[k] = 1;
                       break;
                   }
            }
       }
 }
 cout << endl;
}
 return 0; 
}

 

Published 736 original articles · won praise 123 · views 80000 +

Guess you like

Origin blog.csdn.net/S_999999/article/details/103355095