2018 ACM-ICPC 亚洲区域赛青岛现场赛 —— Problem F. Tournament
题面: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的更多相关文章
- 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)
队名:Unlimited Code Works(无尽编码) 队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...
- Known Notation括号匹配类问题(2014年ACM/ICPC 亚洲区域赛牡丹江)
题意: 给你数字或 * 的串,你可以交换一个*和数字.在最前面添1.在一个地方插入*,问你使串满足入栈出栈的(RNP)运算法则. 思路: 引用:https://blog.csdn.net/u01158 ...
- 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 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛
传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:0 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it
链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 2014ACM/ICPC亚洲区域赛牡丹江现场赛总结
不知道怎样说起-- 感觉还没那个比赛的感觉呢?如今就结束了. 9号.10号的时候学校还评比国奖.励志奖啥的,由于要来比赛,所以那些事情队友的国奖不能答辩.自己的励志奖班里乱搞要投票,自己又不在,真是无 ...
- 2014ACM/ICPC亚洲区域赛牡丹江站汇总
球队内线我也总水平,这所学校得到了前所未有的8地方,因为只有两个少年队.因此,我们13并且可以被分配到的地方,因为13和非常大的数目.据领队谁oj在之上a谁去让更多的冠军.我和tyh,sxk,doub ...
随机推荐
- IrisBlur - 虹膜模糊
[IrisBlur - 虹膜模糊] IrisBlur模拟人眼的虹膜,本质上是一个控制程度更高的FieldBlur,在FieldBlur的基础上暴露了更多的参数. Choose Filter > ...
- 110. Balanced Binary Tree (Tree; DFS)
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- Search Quick Union Find(图的存储结构)
Quick Find:适用于search频繁的情况 每个节点有一个id值,id相同表示两个节点相连通.在union时要将等于某一个id值都改成另一个id值 Quick Union: 适用于union频 ...
- placement new
placement new就是把原本new做的两步工作分开来.第一步你自己分配内存,第二步你调用类的构造函数在自己分配的内存上构建新的对象. class Foo { float f; public: ...
- POJ1163 数学三角求最大路径
描述:输入,行数,之后接数据,第一行一个数据,之后每行加一.5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 思路:简单动态规划问题.dp[i][j]定义为到这个数为止(包括这个数)的最 ...
- 二叉树翻转 · binary tree flipping
[抄题]: 给定一个二叉树,其中所有右节点要么是具有兄弟节点的叶节点(有一个共享相同父节点的左节点)或空白,将其倒置并将其转换为树,其中原来的右节点变为左叶子节点.返回新的根节点. 您在真实的面试中是 ...
- [Java] Java API文档下载方法
Java API文档下载方法:http://jingyan.baidu.com/article/a3aad71ac9e48fb1fb009692.html Oracle : http://www.or ...
- 修复PlatformToolsets丢失问题(为VS2013以上版本安装VC90,VC100编译器)
前段时间测试VS2017的IDE时不小心弄丢了 MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets 下的VC90以及VC100的编译 ...
- (最短路 SPFA)Invitation Cards -- poj -- 1511
链接: http://poj.org/problem?id=1511 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82829#probl ...
- Npoi List DataTable导出一个Excel多个sheet 下载
参考: http://blog.csdn.net/zhouqinghe24/article/details/8649346 参考下载http://www.cnblogs.com/dyllove98/a ...