[Codeforces 639B] Bear and Forgotten Tree 3
[题目链接]
https://codeforces.com/problemset/problem/639/B
[算法]
当d > n - 1或h > n - 1时 , 无解
当2h < d时无解
当d = 1 , n不为2时 , 无解
否则 , 我们先构造一条长度为h的链 , 然后 , 将一条(d - h)的链接到根上 , 再将剩余节点接到根上
时间复杂度 : O(N)
[代码]
#include<bits/stdc++.h>
using namespace std; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ int n , h , d;
read(n); read(d); read(h);
if (d > n - || h > n - )
{
printf("-1\n");
return ;
}
if (h * < d)
{
printf("-1\n");
return ;
}
if (d == && n != )
{
printf("-1\n");
return ;
}
for (int i = ; i <= h + ; i++) printf("%d %d\n",i,i - );
for (int i = ; i <= d - h; i++)
{
if (i == ) printf("%d %d\n",,h + + i);
else printf("%d %d\n",h + i,h + + i);
}
if (d == h)
{
for (int i = d + ; i <= n; i++)
printf("%d %d\n",,i);
} else
{
for (int i = d + ; i <= n; i++)
printf("%d %d\n",,i);
} return ; }
[Codeforces 639B] Bear and Forgotten Tree 3的更多相关文章
- Codeforces 639B——Bear and Forgotten Tree 3——————【构造、树】
Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces 658C Bear and Forgotten Tree 3【构造】
题目链接: http://codeforces.com/contest/658/problem/C 题意: 给定结点数,树的直径(两点的最长距离),树的高度(1号结点距离其他结点的最长距离),写出树边 ...
- CodeForces 658C Bear and Forgotten Tree 3 (构造)
题意:构造出一个 n 个结点,直径为 m,高度为 h 的树. 析:先构造高度,然后再构造直径,都全了,多余的边放到叶子上,注意直径为1的情况. 代码如下: #pragma comment(linker ...
- Code Forces Bear and Forgotten Tree 3 639B
B. Bear and Forgotten Tree 3 time limit per test2 seconds memory limit per test256 megabytes inputst ...
- codeforces 658C C. Bear and Forgotten Tree 3(tree+乱搞)
题目链接: C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3 构造
C. Bear and Forgotten Tree 3 题目连接: http://www.codeforces.com/contest/658/problem/C Description A tre ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E. Bear and Forgotten Tree 2 bfs set 反图的生成树
E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tre ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E - Bear and Forgotten Tree 2 链表
E - Bear and Forgotten Tree 2 思路:先不考虑1这个点,求有多少个连通块,每个连通块里有多少个点能和1连,这样就能确定1的度数的上下界. 求连通块用链表维护. #inclu ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3
C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input ...
随机推荐
- day21 05 员工信息表
day21 05 员工信息表 假设有一个员工信息表,里面有每个员工的名字,id,年龄,电话,还有他们所作的工作,而有时候我们并不需要所有的信息,而想根据某些条件,寻找符合条件即可,即筛选, 比如想要筛 ...
- YOLOv3配置(win10+opencv3.40+cuda9.1+cudnn7.1+vs2015)
最近心血来潮想学一下YOLOv3,于是就去网上看了YOLOv3在win10下的配置教程.在配置过程中塌坑无数,花了很多时间和精力,所以我想就此写一篇博客来介绍在在win10+vs2015的环境下如何配 ...
- 76-Bears/Bulls Power,熊力/牛力震荡指标.(2015.7.1)
Bears/Bulls Power 熊力/牛力震荡指标 Power,熊力/牛力震荡指标.(2015.7.1)" title="76-Bears/Bulls Power,熊力/牛力震 ...
- BUAA_OO_博客作业四
BUAA_OO_博客作业四 1 第四单元两次作业的架构设计 1.1 第13次作业 类图 作业要求:通过实现UmlInteraction这个官方提供的接口,来实现自己的UmlInteraction解 ...
- [TyvjP1050] 最长公共子序列(DP)
传送门 f[i][j] 表示第 1 个串匹配到第 i 位,第 2 个串匹配到第 j 位的答案. f[i][j] = max(f[i - 1][j], f[i][j - 1]) (a[i] != ...
- zoj 2676 二分+ISAP模板求实型参数的最小割(0-1分数规划问题)(可做ISAP模板)
/* 参考博文:http://www.cnblogs.com/ylfdrib/archive/2010/09/01/1814478.html 以下题解为转载代码自己写的: zoj2676 胡伯涛论文& ...
- 关于java对于大数处理的相关程序和用法
<span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; l ...
- stl lower_bound()和up_bound()
iter=data.erase(iter);删掉 转载:http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html STL中的每个算法 ...
- springData Jpa 快速入门
前言: 数据持久化的操作,一般都要由我们自己一步步的去编程实现,mybatis通过我们编写xml实现,hibernate也要配置对应的xml然后通过创建session执行crud操作.那么有没有这样一 ...
- 开发辅助网站---programcreek
开发中让我们事半功倍的工具网站,开发中经常遇到api如何使用,很好的解决这个问题.java代码api案例网,提供最简单的demo,很不错分享一下,大家可以用用. http://www.programc ...