F



i



v



e



-



gr



ea



t
蓝桥杯比赛安排(深搜)

问题描述
  设有有2 n(n<=6)个球队进行单循环比赛,计划在2 n – 1天内完成,
每个队每天进行一场比赛。设计一个比赛的安排,使在2 n – 1天内每个队都与不同的对手比赛。
输入格式
  输入文件matchplan.in共一行,输入n的数值。
输出格式
  输出文件matchplan.out共(2 n – 1)行,第i行输出第i天的比赛安排。
  格式为: A-B,C-D,……。其中i是天数,A,B分别为比赛双方的编号,每行共2 n-1个比赛场次。
样例输入
2
样例输出
<1>1-2,3-4
<2>1-3,2-4
<3>1-4,2-3

#include<stdio.h>
int b[30][30]={0};//标记曾经匹配过 
int dq[30]={0};//当天匹配标记 
int a[30];//被匹配者  (小组队伍红方) 
int a1[30];//匹配者 (小组队伍蓝方) 
int tw; //比赛小组队伍 (10支队伍 5队小组队伍) 
int T=0;//判断当前天数比赛 第一顺序方案是否已制定 
void f(int pos )
{int i,j,bt;//当前被匹配者 用于清除标记 

if(tw<pos)//pos 代表当前选第几组的比赛
{

    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;&lt;%d&gt;&quot;</span><span class="token punctuation">,</span>a1<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>T<span class="token operator">=</span>a1<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//&#x5F53;&#x524D;&#x5929;&#x6570;&#x7B2C;&#x4E00;&#x987A;&#x5E8F;&#x8BA1;&#x5212;&#x5DF2;&#x5B9A; </span>
   <span class="token keyword">for</span><span class="token punctuation">(</span>i<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>i<span class="token operator">&lt;=</span>tw<span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d-%d &quot;</span><span class="token punctuation">,</span>a<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">,</span>a1<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//&#x8F93;&#x51FA;&#x5339;&#x914D;&#x5C0F;&#x7EC4;&#x961F;&#x4F0D; </span>

     b<span class="token punctuation">[</span>a<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">[</span>a1<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span> b<span class="token punctuation">[</span>a1<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">[</span>a<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//&#x76F8;&#x4E92;&#x6807;&#x8BB0;&#x4E3A;&#x66FE;&#x7ECF;&#x5339;&#x914D; </span>
    <span class="token punctuation">}</span>
      <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;\n&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span>
<span class="token keyword">else</span>
<span class="token punctuation">{</span> <span class="token keyword">for</span><span class="token punctuation">(</span>i<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>i<span class="token operator">&lt;=</span><span class="token number">2</span><span class="token operator">*</span>tw<span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>dq<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token operator">==</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>a<span class="token punctuation">[</span>pos<span class="token punctuation">]</span><span class="token operator">=</span>i<span class="token punctuation">;</span>dq<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>bt<span class="token operator">=</span>i<span class="token punctuation">;</span><span class="token keyword">break</span><span class="token punctuation">;</span><span class="token punctuation">}</span> <span class="token comment" spellcheck="true">//&#x6309;&#x987A;&#x5E8F;&#x62FF;&#x51FA;&#x88AB;&#x5339;&#x914D;&#x7740;&#xFF1B; </span>
    <span class="token keyword">for</span><span class="token punctuation">(</span>i<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>i<span class="token operator">&lt;=</span><span class="token number">2</span><span class="token operator">*</span>tw<span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token comment" spellcheck="true">//&#x5339;&#x914D;&#x8005;&#x5FAA;&#x73AF; </span>
     <span class="token keyword">if</span><span class="token punctuation">(</span> b<span class="token punctuation">[</span>a<span class="token punctuation">[</span>pos<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token operator">==</span><span class="token number">0</span><span class="token operator">&amp;&amp;</span>dq<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token operator">==</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token comment" spellcheck="true">//&#x5224;&#x65AD;&#x66FE;&#x7ECF;&#x662F;&#x5426;&#x5339;&#x914D;&#x8FC7;&#x5E76;&#x4E14;&#x5F53;&#x524D;&#x662F;&#x5426;&#x88AB;&#x5339;&#x914D; </span>
     <span class="token punctuation">{</span>a1<span class="token punctuation">[</span>pos<span class="token punctuation">]</span><span class="token operator">=</span>i<span class="token punctuation">;</span>dq<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
     <span class="token function">f</span><span class="token punctuation">(</span>pos<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//&#x8BD5;&#x6267;&#x884C;&#x4E0B;&#x4E00;&#x7EC4;&#x6BD4;&#x8D5B;&#xFF1B; </span>
       dq<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//&#x6E05;&#x9664;&#x5F53;&#x524D;&#x5339;&#x914D;&#x8005;</span>
     <span class="token keyword">if</span><span class="token punctuation">(</span>T<span class="token operator">==</span>a1<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">{</span>i<span class="token operator">=</span><span class="token number">2</span><span class="token operator">*</span>tw<span class="token punctuation">;</span><span class="token punctuation">}</span> <span class="token comment" spellcheck="true">//&#x82E5;&#x5F53;&#x5929;&#x7B2C;&#x4E00;&#x987A;&#x5E8F;&#x65B9;&#x6848;&#x5DF2;&#x786E;&#x5B9A;&#x5219;&#x65E0;&#x9700;&#x91CD;&#x590D;&#x8BBE;&#x8BA1;&#x65B9;&#x6848; </span>
     <span class="token punctuation">}</span>

     dq<span class="token punctuation">[</span>bt<span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//&#x6E05;&#x9664;&#x5F53;&#x524D;&#x88AB;&#x5339;&#x914D;&#x8005; </span>
<span class="token punctuation">}</span>

}

int main()
{
int n,i,j;
scanf("%d",&n);
tw=n;//小组队伍组数
n=n*2-1;
for(i=1;i<=n;i++)//循环天数;
f(1);//从第一组队伍开始

return 0;
}