[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 ...
随机推荐
- 零基础入门学习Python(36)--类和对象:给大家介绍对象
知识点 Python3 面向对象 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的.本章节我们将详细介绍Python的面向对象编程. 如果你以前 ...
- 89-Relative Vigor Index 相对活力指数指标.(2015.7.4)
Relative Vigor Index 相对活力指数指标 ~计算: RVI = (CLOSE-OPEN)/(HIGH-LOW) RVIsig=SMA(RVI,N) ~思想: 牛市中,收盘>开盘 ...
- hibernate-validator验证请求参数
开发接口要进行请求参数内容格式校验,比如在接收到请求参数后依次需要进行数据内容判空.数据格式规范校验等,十分麻烦,于是尝试用hibernate-validator进行参数校验,简单记录一下使用步骤: ...
- 易接SDK ios9以上无法弹出充值界面的一种情况
充值需要用到http请求: 打开info.plist, 在app tansport security setting 这个项 , 加入 NSAllowsArbitraryLoads YES
- SpringBoot Data JPA 关联表查询的方法
SpringBoot Data JPA实现 一对多.多对一关联表查询 开发环境 IDEA 2017.1 Java1.8 SpringBoot 2.0 MySQL 5.X 功能需求 通过关联关系查询商店 ...
- 2018/2/17 SpringCloud的一个简单小介绍
在学习SpringCloud之前,我以为SpringCloud是与Double一样,只是个单纯的RPC框架.但在今天的学习中,我发现并非如此,事实上,SpringCloud是多个框架的集合,感觉Spr ...
- springMVC @Value的使用
@Value 功能:将一个SpEL(SpEL:spring表达式类似于ognl)表达式结果映射到功能处理方法的参数上 例子:获取系统参数'java.vm.version'的值给到变量jvmVersio ...
- Linux下汇编语言学习笔记24 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- FZU Problem 2171 防守阵地 II (线段树区间更新模板题)
http://acm.fzu.edu.cn/problem.php?pid=2171 成段增减,区间求和.add累加更新的次数. #include <iostream> #include ...
- Meeting 加虚拟边
Bessie and her friend Elsie decide to have a meeting. However, after Farmer John decorated his fence ...