题面:http://acm.zju.edu.cn/contest-materials/qd2018/qd2018_problems.pdf

题意:

n个骑士决斗K轮

要求是每个骑士只能跟另外一个骑士决斗一次

每轮必须有 n/2 场决斗

如果在某轮A和B单挑,C和D单挑

那么在下面的论场中必然有A和C单挑同时B和D单挑

思路:

用一个set存每个骑士还没单挑过的其他骑士编号,一个set存每轮还没有单挑过的骑士

先预处理第一轮的21436587······

第一个骑士每轮单挑必然是单挑的轮数+1(如第一轮单挑的是2即1+1)

这样才能满足字典序最小的要求

然后把第一个骑士单挑的第X个骑士的上一个和第一个的上一个进行单挑

然后找本轮还没单挑的编号最小的骑士去单挑本轮还没单挑的他还没单挑过的最小的(好拗口啊ORZ)

代码上能看的比较清楚,建议直接分析代码

另外如果k>=lowbit(n) 那么绝对不可能安排上

具体可以自己打表看看

代码(注意这不是最终代码):

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define it iterator
#define ll long long
#define eb emplace_back
#define lowbit(x) x & -x
#define all(x) x.begin(),x.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define per(x,a,b) for(int x = a; x <= b; x++)
#define rep(x,a,b) for(int x = a; x >= b; x--)
#define IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) const int birth = ;
const int mo = ;
const int maxn = 1e4 + ;
const int mod = 1e9 + ;
const int INF = 0x3fffffff;
const double eps = 1e-; int ch[maxn][maxn]; //******************THE PROGRAM BEGINING****************** int main()
{
//cout << (lowbit(12)) << endl;
int t;
cin >> t;
while (t--)
{
int n, k;
set<int> s[maxn];
set<int> e;
cin >> n >> k; if (k >= (lowbit(n)))
{
cout << "Impossible" << endl;
continue;
} if (lowbit(n) == || k == )
{
per(i, , n)
{
if (i & )
cout << i + ;
else
cout << i - ;
if (i != n)
cout << " ";
}
cout << endl;
continue;
}
else
{
per(i, , n)
{
if (i & )
ch[][i] = i + ;
else
{
ch[][i] = i - ;
}
per(j, , n)
{
if (i == j || j == ch[][i])
continue;
s[i].insert(j);
}
}
int x = k - ;
int num = ;
int pos = ;
while (x--)
{
e.clear();
per(i, , n)
e.insert(i);
e.erase(num);
ch[pos][] = num;
ch[pos][num] = ;
s[num].erase();
ch[pos][ch[pos - ][]] = ch[pos - ][num];
e.erase(ch[pos - ][num]);
ch[pos][ch[pos - ][num]] = ch[pos - ][];
e.erase(ch[pos - ][]);
s[ch[pos - ][]].erase(ch[pos - ][num]);
s[ch[pos - ][num]].erase(ch[pos - ][]);
while (!e.empty())
{
int head = *e.begin();
int tail;
e.erase(head);
for (set<int>::iterator it = s[head].begin(); it != s[head].end(); it++)
{
if (e.count(*it))
{
tail = *it;
break;
}
} e.erase(tail);
ch[pos][head] = tail;
ch[pos][tail] = head;
s[head].erase(tail);
s[tail].erase(head);
ch[pos][ch[pos - ][head]] = ch[pos - ][tail];
e.erase(ch[pos - ][head]);
ch[pos][ch[pos - ][tail]] = ch[pos - ][head];
e.erase(ch[pos - ][tail]);
s[ch[pos - ][tail]].erase(ch[pos - ][head]);
s[ch[pos - ][head]].erase(ch[pos - ][tail]);
}
num++;
pos++;
} for (int i = ; i < k; i++)
{
for (int j = ; j <= n; j++)
{
cout << ch[i][j];
if (j != n)
cout << " ";
}
cout << endl;
}
}
} return ;
}

但是呢,这个方法从时间上讲完全是不够用的,然后通过上面的进行打表,发现了一个天大的咪咪

#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std; int ch[][]; //******************THE PROGRAM BEGINING****************** int main()
{
int t;
cin >> t;
while (t--)
{
int n, k;
scanf("%d %d", &n, &k); if (k >= (n & -n))
{
puts("Impossible");
continue;
} if ((n & -n) == || k == )
{
for(int i = ; i <= n; i++)
{
if (i & )
printf("%d", i + );
else
printf("%d", i - );
if (i != n)
printf(" ");
}
printf("\n");
continue;
}
else
{
for (int i = ; i <= n; i++)
{
if (i & )
{
ch[][i] = i;
ch[][i] = i + ;
}
else
{
ch[][i] = i;
ch[][i] = i - ;
}
} int x = ;
while (x <= k)
{
for (int i = x; i <= x * - ; i++)
{
for (int j = ; j <= n; j += * x)
{
for (int k = j; k < j + x; k++)
{
ch[i][k] = ch[i - x][k + x];
}
for (int k = j + x; k < j + * x; k++)
{
ch[i][k] = ch[i - x][k - x];
}
}
}
x *= ;
} for (int i = ; i <= k; i++)
{
for (int j = ; j <= n; j++)
{
printf("%d", ch[i][j]);
if (j != n)
printf(" ");
}
printf("\n");
}
}
} return ;
}

其实就是定长翻倍交换左右块就好了

先打表前两行

第三第四行为2*2的块交换

第五到第八行为4*4的块交换

依次推下去即可

2018 ACM-ICPC 亚洲区域赛青岛现场赛 —— Problem F. Tournament的更多相关文章

  1. 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)

    队名:Unlimited Code Works(无尽编码)  队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...

  2. Known Notation括号匹配类问题(2014年ACM/ICPC 亚洲区域赛牡丹江)

    题意: 给你数字或 * 的串,你可以交换一个*和数字.在最前面添1.在一个地方插入*,问你使串满足入栈出栈的(RNP)运算法则. 思路: 引用:https://blog.csdn.net/u01158 ...

  3. Digit sum (第 44 届 ACM/ICPC 亚洲区域赛(上海)网络赛)进制预处理水题

    131072K   A digit sum S_b(n)Sb​(n) is a sum of the base-bb digits of nn. Such as S_{10}(233) = 2 + 3 ...

  4. 2018 ACM 国际大学生程序设计竞赛上海大都会赛

    传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:0 ...

  5. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it

    链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...

  6. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...

  7. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  8. 2014ACM/ICPC亚洲区域赛牡丹江现场赛总结

    不知道怎样说起-- 感觉还没那个比赛的感觉呢?如今就结束了. 9号.10号的时候学校还评比国奖.励志奖啥的,由于要来比赛,所以那些事情队友的国奖不能答辩.自己的励志奖班里乱搞要投票,自己又不在,真是无 ...

  9. 2014ACM/ICPC亚洲区域赛牡丹江站汇总

    球队内线我也总水平,这所学校得到了前所未有的8地方,因为只有两个少年队.因此,我们13并且可以被分配到的地方,因为13和非常大的数目.据领队谁oj在之上a谁去让更多的冠军.我和tyh,sxk,doub ...

随机推荐

  1. 在 springboot 中如何整合 shiro 应用 ?

     Shiro是Apache下的一个开源项目,我们称之为Apache Shiro. 它是一个很易用与Java项目的的安全框架,提供了认证.授权.加密.会话管理,与spring Security 一样都是 ...

  2. 29. Divide Two Integers (INT; Overflow, Bit)

    Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...

  3. 创建和运行Java项目

    ---------siwuxie095                     首先在左侧的工程管理面板 Package Explorer 中,右键->New->Java Project ...

  4. 27-python 画图

    绝佳教程:http://pyecharts.org/#/zh-cn/prepare?id=%E4%BD%BF%E7%94%A8%E4%B8%BB%E9%A2%98安装 pyecharts pip in ...

  5. [SoapUI] EndPoint不需要在配置文件中设置不同环境的值,SoapUI自带此参数的设置

    在Environments里面设置就好了

  6. web02

    高内聚,低耦合 写what 不写how 我们只关心他是什么,得到什么,我们并不关心怎么去得到的 ,那个细节去怎么得的, 都应该在这个层面上屏蔽掉,要关心的时候在点进去,这样就一层层的结构良好的代码 d ...

  7. TWO PHASES OF ANGULAR 2 APPLICATIONS

    Angular 2 separates updating the application model and reflecting the state of the model in the view ...

  8. background image

    http://www.ajaxblender.com/bgstretcher-2-jquery-stretch-background-plugin-updated.html http://blog.d ...

  9. GO语言使用gopsutil包进行机器信息采集

    GO语言本身拥有极强的性能,非常适合做一些后端的数据采集管理以及运维系统. 其中会面临对当前系统信息的采集,我在这里使用的是GO的工具包 gopsutil 贴出一套测试代码,抛砖引玉: import ...

  10. Python中where()函数的用法

    where()的用法 首先强调一下,where()函数对于不同的输入,返回的只是不同的. 1当数组是一维数组时,返回的值是一维的索引,所以只有一组索引数组 2当数组是二维数组时,满足条件的数组值返回的 ...