noip1996 Competition Arrangement-popularization Group + raise group (hash weight)

Source: Internet
Author: User
Tags hash printf time limit
A1107. Schedule time limit: 1.0s memory limit: 256.0MB Total commits: 388 AC: 179 average score: 57.73 share the subject to: View unformatted questions submit questions source N OIP1996 Raise group Problem description There are 2 N (n<=6) teams in a single cycle, scheduled to be completed within 2 n–1 days, and each team play a game every day. Design a match arrangement so that each team will compete with different opponents within 2 n–1 days.
For example, the match arrangement at n=2:
Team 1 2 3 4
Race 1==2 3==4 Day
1==3 2==4 two days
1==4 2==3 Three day input format the first line of input contains an integer n. Output format output 2^n-1 lines, each line beginning with a pair of angle brackets, inside the output number of days. Then write out the arrangements for the day. The detailed format is shown in the sample. There are several scenarios that output the smallest dictionary order. Sample input 2 sample output <1>1-2,3-4
<2>1-3,2-4
<3>1-4,2-3 data size and conventions n<=6


Parsing: Hash of the weight.

Use B[i][j] to record whether I and J have played, total N teams.

Although not mentioned in the title, the output should be output in dictionary order.

Code:

#include <cstdio>
#include <cstring>
#define MAXN
using namespace std;
BOOL A[MAXN],B[MAXN][MAXN];
int main ()
{
  int n,i,j,k,s,sum;
  scanf ("%d", &n);
  s=1<<n;
  for (i=1;i<s;i++)
     {
       memset (a,0,sizeof (a));
       printf ("<%d>", I);
       sum=0;
       for (j=1;j<s;j++) for
         (k=j+1;k<=s;k++)
           if (!a[j] &&!a[k] &&!b[j][k] &&!b[k][ J])
             {
               a[j]=a[k]=1;
               b[j][k]=b[k][j]=1,sum++;
               printf ("%d-%d", j,k);
               if (sum< (s>>1)) printf ("");
             }
        printf ("\ n");     
     }
  return 0;
}


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.