CF850D Tournament Construction
CF850D Tournament Construction
题目传送门
挺难的一道构造题。
题目大意:
给定 mmm 个数的一个非负整数集合,不超过 303030。你需要构造一个竞赛图,满足:所有点的出度去重后等于该集合。m≤31m≤31m≤31
前置芝士:
兰道定理(Landau’s Theorem):
设点 iii 的出度为 did_idi,那么对于任意 1≤i≤n1≤i≤n1≤i≤n,有∑j=1idi≥i×(i−1)2∑^i_{j=1}d_i≥\frac{i\times(i−1)}{2}∑j=1idi≥2i×(i−1)。且当 i=ni=ni=n 时取等。
证明请自行百度
竞赛图: 有向完全图。
思路:
由于题中给出的是去重之后的出度集合,我们需要用这个集合构造出一个合法的出度数组 ddd。每个数至少用一次,因此可以做一个类似背包的东西来构造这个 ddd。然后找到第一个满足 di>uid_i>u_idi>ui 的位置,然后找到最大的 jjj,满足 ui=uiu_i=u_iui=ui,接下来找到第一个满足 dk<ukd_k<u_kdk<uk 的位置,有 j<kj<kj<k 且 uj+2≤uku_j+2≤u_kuj+2≤uk,那么必然存在点 xxx 满足 kkk 向 xxx 连边且 xxx 向 jjj 连边。把这两条边翻转即可。这样做只会改变 kkk 和 jjj 的度数,对 xxx 并无影响.
重复上面的过程直到 ddd 与 uuu 完全相同。
代码:
#include<bits/stdc++.h>
#define freo(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define ll long long
using namespace std;
const int maxn=65,maxm=1835;
int n,m,a[maxn],f[maxn][maxn][maxm],g[maxn][maxn][maxm],d[maxn],u[maxn],e[maxn][maxn];
inline ll read()
{ll ret=0;char ch=' ',c=getchar();while(!(c<='9'&&c>='0')) ch=c,c=getchar();while(c<='9'&&c>='0') ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();return ch=='-'?-ret:ret;
}
int main()
{m=read();for(int i=1; i<=m; i++) a[i]=read();sort(a+1,a+m+1);f[0][0][0]=1;for(int i=1; i<=m; i++)for(int j=i; j<maxn; j++)for(int k=i-1; k<j; k++)for(int y=k*(k-1)/2,x=(j-k)*a[i]+y; x<maxm; x++,y++)if(f[i-1][k][y])f[i][j][x]=1,g[i][j][x]=j-k;n=m;while(n<maxn&&!f[m][n][n*(n-1)/2]) n++;if(n==maxn) {printf("=(");return 0;}printf("%d\n",n);for(int i=m,j=n,k=n*(n-1)/2; i>=1; i--) {for(int x=0; x<g[i][j][k]; x++) d[j-x]=a[i];int tmp=k;k-=g[i][j][tmp]*a[i],j-=g[i][j][tmp];}sort(d+1,d+n+1);for(int i=1; i<=n; i++) {u[i]=i-1;for(int j=1; j<i; j++) e[i][j]=1;}while(1) {int tmp1=1,tmp2=n,tmp3=1,tmp4=n;while(tmp1<=n&&d[tmp1]<=u[tmp1]) tmp1++;if(tmp1>n) break;while(u[tmp2]!=u[tmp1]) tmp2--;while(d[tmp3]>=u[tmp3]) tmp3++;while(!(e[tmp3][tmp4]&&e[tmp4][tmp2])) tmp4--;e[tmp3][tmp4]=0;e[tmp4][tmp3]=1;e[tmp4][tmp2]=0;e[tmp2][tmp4]=1;u[tmp3]--;u[tmp2]++;}for(int i=1; i<=n; i++) {for(int j=1; j<=n; j++) putchar(e[i][j]+'0');putchar('\n');}return 0;
}
CF850D Tournament Construction相关推荐
- 第十一届山东省大学生程序设计竞赛 L. Construction of 5G Base Stations(概率期望,递推前缀和优化)
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 第十一届山东省大学生程序设计竞赛 L. Construction of 5G Base Station ...
- 微生物相关网络构建教程中文Microbial association network construction tutorial
原文为自Microbial association network construction tutorial http://psbweb05.psb.ugent.be/conet/microbial ...
- Fast construction of FM-index for long sequence reads
参考:https://watermark.silverchair.com/btu541.pdf?token=AQECAHi208BE49Ooan9kkhW_Ercy7Dm3ZL_9Cf3qfKAc48 ...
- 图像拼接--Construction and Refinement of Panoramic Mosaics with Global and Local Alignment
Construction and Refinement of Panoramic Mosaics with Global and Local Alignment International Confe ...
- 【CF913F】Strongly Connected Tournament 概率神题
[CF913F]Strongly Connected Tournament 题意:有n个人进行如下锦标赛: 1.所有人都和所有其他的人进行一场比赛,其中标号为i的人打赢标号为j的人(i<j)的概 ...
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...
- boost::type_erasure模块construction相关的测试程序
boost::type_erasure模块construction相关的测试程序 实现功能 C++实现代码 实现功能 boost::type_erasure模块construction相关的测试程序 ...
- SCons: A software construction tool
SCons: A software construction tool What is SCons? SCons is an Open Source software construction too ...
- Tournament CodeForces - 27B(dfs)
The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. n best pa ...
最新文章
- ios 仿电脑qq登录界面_1、IOS开发--iPad之仿制QQ空间(登录界面搭建+登录逻辑实现)...
- python适合多大的人学-学Python编程孩子几岁最合适?
- python可以做什么工作好-Python可以做什么工作?Python有哪些方向?
- cisco 单词 词典
- c语言指针写鞍点,c语言——鞍点
- Bourbon: 让你的sass更简洁
- Java程序员从笨鸟到菜鸟之(五十一)细谈Hibernate(二)开发第一个hibernate基本详解...
- 平板直撑的腰椎问题(塌腰)
- oracle10g 如何打开,oracle10g oem无法打开解决方法
- yum mysql 无法启动失败_Linux下MySQL数据库yum升级后无法启动解决办法
- 小米3g刷高格固件_今天小米路由器3G到手就刷 老毛子 固件。
- 论文复现——CE-FPN: Enhancing Channel Information for Object Detection
- input框不允许输入负数
- LeetCode - Pascal's Trangle2
- nvm介绍及常用命令
- PHP实现发送邮件功能代码|PHP怎么实现QQ邮件发送|Php发送邮件代码
- 达梦数据库之备份还原
- 关于腾讯TBS中,加载失败问题(64位手机无法加载x5)
- 音频单元组件服务参考(Audio Unit Component Services Reference)
- 怎么学好计算机专业?