题目大意:构造一个点数为dn+1的无向图,无向图中点的度数的集合等于给出的集合d。

题目分析:

  当n=0的时候,一个点即可。

  当n=1的时候,答案是一个包含d1+1个点的完全图。

  否则将d2~dn-1的度数减去d1,然后构造d1个点和dn-dn-1个点,将前d1个点与任何一个点都连上边,这样就有了d1和dn。

代码:

 #include<bits/stdc++.h>
using namespace std; int n;
int d[]; void read(){
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&d[i]);
} int last = ; vector<pair<int,int> > edge; void dfs(int l,int r){
if(l > r){last = ;return;}
if(l == r){
last = d[l]+;
for(int i=;i<=last;i++)
for(int j=i+;j<=last;j++) edge.push_back(make_pair(i,j));
return;
}
for(int i=l+;i<r;i++) d[i] -= d[l];
dfs(l+,r-);
for(int i=l+;i<r;i++) d[i] += d[l];
int p1 = d[r]-d[r-],p2 = d[l];
last += p1;
for(int i=;i<=last;i++){
for(int j=last+;j<=last+p2;j++) edge.push_back(make_pair(i,j));
}
for(int i=last+;i<=last+p2;i++){
for(int j=i+;j<=last+p2;j++) edge.push_back(make_pair(i,j));
}
last += p2;
} void work(){
dfs(,n);
printf("%d\n",edge.size());
for(int i=;i<edge.size();i++)
printf("%d %d\n",edge[i].first,edge[i].second);
} int main(){
read();
work();
return ;
}

Codeforces976D Degree Set 【构造】的更多相关文章

  1. 2015多校.MZL's endless loop(欧拉回路的机智应用 || 构造)

    MZL's endless loop Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  2. Codeforces Round #306 (Div. 2) D. Regular Bridge 构造

    D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  3. URAL 1779 F - The Great Team 构造

    F - The Great TeamTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...

  4. HDU 2454 Degree Sequence of Graph G(Havel定理 推断一个简单图的存在)

    主题链接:pid=2454">http://acm.hdu.edu.cn/showproblem.php?pid=2454 Problem Description Wang Haiya ...

  5. 文本分类学习 (十)构造机器学习Libsvm 的C# wrapper(调用c/c++动态链接库)

    前言: 对于SVM的了解,看前辈写的博客加上读论文对于SVM的皮毛知识总算有点了解,比如线性分类器,和求凸二次规划中用到的高等数学知识.然而SVM最核心的地方应该在于核函数和求关于α函数的极值的方法: ...

  6. ZOJ 3212 K-Nice(满足某个要求的矩阵构造)

    H - K-Nice Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Sta ...

  7. CF1082D:Maximum Diameter Graph (简单构造)

    Graph constructive problems are back! This time the graph you are asked to build should match the fo ...

  8. Codeforces Round #306 (Div. 2)A B C D 暴力 位/暴力 暴力 构造

    A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  9. Codeforces 550D —— Regular Bridge——————【构造】

     Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. IIS导入.pfx证书时报错:"A specified logon session does not exist. It may already have been terminated."

    在IIS中可以直接导入.pfx文件来给站点绑定https协议: 如果在导入.pfx文件时,不选择"Allow this certificate to be exported"的话 ...

  2. Luogu3352 ZJOI2016 线段树 概率、区间DP

    传送门 考虑对于每一个位置\(i\),计算所有可能的结果出现的概率. 定义一个区间\([l,r]\)为对于\(x\)的极大区间,当且仅当\(\max \limits _{i=l}^r \{a_i\} ...

  3. MySQL调优基础, 与hikari数据库连接池配合

    1.根据硬件配置系统参数 wait_timeout  非交互连接的最大存活时间, 10-30min max_connections   全局最大连接数 默认100 根据情况调整 back_log   ...

  4. ngx_lua 模块

    ngx_lua模块的原理: 1.每个worker(工作进程)创建一个Lua VM,worker内所有协程共享VM:2.将Nginx I/O原语封装后注入 Lua VM,允许Lua代码直接访问:3.每个 ...

  5. springboot @Value 获取计算机中绝对路径文件的内容

    默认情况下使用 @Value("aaa.txt") private Resource txtResource; 这样获取到的是项目classpath 下的 aaa.txt 如果想获 ...

  6. 【工作感悟】Android 开发者,如何提升自己的职场竞争力?

    前言 该文章是笔者参加 Android 巴士线下交流会成都站 的手写讲稿虚拟场景,所以大家将就看一下. 开始 大家好,我是刘世麟,首先感谢安卓巴士为我们创造了这次奇妙的相遇.现场的氛围也让我十分激动. ...

  7. 基于RC4加密算法的图像加密

    基于RC4加密算法的图像加密 某课程的一个大作业内容,对图像加密.项目地址:https://gitee.com/jerry323/RC4_picture 这里使用的是RC4(流.对称)加密算法,算法流 ...

  8. CentOS 6下gcc升级的操作记录(由默认的4.4.7升级到6.4.0版本)

    机房一台centos6.9机器部署了jenkins发布系统,开发人员在用node编译js,发现依赖的gcc版本低了,故需要将gcc升级到高版本(至少5.0版本以上),这里选择升级到6.4.0版本,下面 ...

  9. oracle ocp视频教程笔记

    show parameter user user_dump_dest  string  /u01/app/oracle/diag/rdbms/orcl/orcl/trace oracle日志存放位置d ...

  10. C. The Tower is Going Home

    链接 [http://codeforces.com/contest/1075/problem/C] 题意 有个1e9*1e9的棋盘(1,1)位置在左下角也就是车这枚棋子的位置,然后有n个在某一列后面划 ...