Codeforces976D Degree Set 【构造】
题目大意:构造一个点数为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 【构造】的更多相关文章
- 2015多校.MZL's endless loop(欧拉回路的机智应用 || 构造)
MZL's endless loop Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- 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 ...
- URAL 1779 F - The Great Team 构造
F - The Great TeamTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...
- HDU 2454 Degree Sequence of Graph G(Havel定理 推断一个简单图的存在)
主题链接:pid=2454">http://acm.hdu.edu.cn/showproblem.php?pid=2454 Problem Description Wang Haiya ...
- 文本分类学习 (十)构造机器学习Libsvm 的C# wrapper(调用c/c++动态链接库)
前言: 对于SVM的了解,看前辈写的博客加上读论文对于SVM的皮毛知识总算有点了解,比如线性分类器,和求凸二次规划中用到的高等数学知识.然而SVM最核心的地方应该在于核函数和求关于α函数的极值的方法: ...
- ZOJ 3212 K-Nice(满足某个要求的矩阵构造)
H - K-Nice Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Sta ...
- CF1082D:Maximum Diameter Graph (简单构造)
Graph constructive problems are back! This time the graph you are asked to build should match the fo ...
- 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 ...
- Codeforces 550D —— Regular Bridge——————【构造】
Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
随机推荐
- kubernetes 集群机器重启后磁盘盘符变化
1.[root@pserver78 ~]# kubectl -n rook-ceph exec -it rook-ceph-tools-c95b8496b-g4stp -- ceph osd tree ...
- SkylineGlobe 如何实现工程进度管理或者说是对象生命周期管理
SkylineGlobe 的 TerraExplorer Pro里面,给我们提供了一个Timespan Tags工具,通过这个工具,我们可以设置ProjectTree任务组对象的生命周期: 然后通过调 ...
- linux shell的here document用法
转载自: http://my.oschina.net/u/1032146/blog/146941 什么是Here Document?Here Document 是在Linux Shell 中的一种特殊 ...
- CSV文件解析
CSV(逗号分隔值文件格式) 逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也可以不是逗号),其文件以纯文本形式存储表格数据(数字和 ...
- Ionic 添加java原生代码 报support.v4不存在问题
在做Ionic Hybird app开发过程中不可避免的使用一些原生代码的问题,那么怎么添加原生代码呢? 答案很简单:1.将原生代码直接拷贝到项目下的 你的项目名/platforms/android/ ...
- Linux性能评测工具之一:gprof篇
这些天自己试着对项目作一些压力测试和性能优化,也对用过的测试工具作一些总结,并把相关的资料作一个汇总,以便以后信手拈来! 1 简介 改进应用程序的性能是一项非常耗时耗力的工作,但是究竟程序中是哪些函数 ...
- mysql 常用的几个函数
IF 函数 语法:`IF`(expr1,expr2,expr3); 当expr1为ture时,值为expr2,当expr1为false时,值为expr3. 如: IFNULL 函数 语法:IFNULL ...
- Java 大数、高精度模板
介绍: java中用于操作大数的类主要有两个,一个是BigInteger,代表大整数类用于对大整数进行操作,另一个是BigDecimal,代表高精度类,用于对比较大或精度比较高的浮点型数据进行操作.因 ...
- hibernate 解决 java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.xxx 这类的问题
<!-- 解决 java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.intern ...
- nginx反向代理中proxy_set_header 运维笔记
Nginx proxy_set_header:即允许重新定义或添加字段传递给代理服务器的请求头.该值可以包含文本.变量和它们的组合.在没有定义proxy_set_header时会继承之前定义的值.默认 ...