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 ...
随机推荐
- application获取资源
通过application获取资源,它的根路径是WebContent,它可以获取web-inf下的资源 通过getclassload()获取资源,它的根路径是classes,不能获取web-inf下的 ...
- nodejs-supervisor
小技巧——使用 supervisor 如果你有 PHP 开发经验,会习惯在修改 PHP 脚本后直接刷新浏览器以观察结果,而你在开发 Node.js 实现的 HTTP 应用时会发现,无论你修改了代码的哪 ...
- Unix高级编程Note2
[Unix Note2] 1.信号屏蔽 2.信号不会排队,即产生同时产生10次,会被合并为1次. 3.sigsuspend,sigsuspend后,进程就挂在那里,等待着开放的信号的唤醒.系统在接收到 ...
- python报OperationalError: (1366, "Incorrect string value..."的问题解决
一.环境及问题描述 1. 环境 操作系统:win10,64bit. python版本:2.7.15 mysql版本:5.7.23 2. 问题描述 使用python从某个数据文件读取数据,处理后,用My ...
- 安装bcmath 扩展
1.在php源码包中,默认就包含bcmath扩展的安装文件,只需手动安装一下即可 cd /root/build2/php-/ext/bcmath // 进入PHP的源码包目录中的bcmatch扩展目录 ...
- Java Thread系列(十)Future 模式
Java Thread系列(十)Future 模式 Future 模式适合在处理很耗时的业务逻辑时进行使用,可以有效的减少系统的响应时间,提高系统的吞吐量. 一.Future 模式核心思想 如下的请求 ...
- MVC和WebApi 使用get和post 传递参数(转)
出处:http://blog.csdn.net/qq373591361/article/details/51508806 我们总结一下用js请求服务器的传参方法. Get方式 Get主要是用来查询,一 ...
- linux中的 tar命令的 -C 参数,以及其它一些参数
tar命令的-C参数 $ tar -cvf file2.tar /home/usr2/file2 tar: Removing leading '/' from members names hom ...
- Web挖掘
Web挖掘 Web挖掘的目标是从Web的超链接.网页内容和使用日志中探寻有用的信息.依据Web挖掘任务,可以划分为三种主要类型:Web结构挖掘.Web内容挖掘和Web使用挖掘.Web结构挖掘简单的说就 ...
- Swift实现UIKit Dynamic动画
iOS7引入了UIKit Dynamics,可以帮助开发者开发出更接近真实世界的动画效果.之前,用户如果要做出这样的效果,需要话很多的时间在物理计算和Core Animation上.现在,所有的一切都 ...