【Codeforces 639B】Bear and Forgotten Tree 3
【链接】 我是链接,点我呀:)
【题意】
【题解】
首先,因为高度是h
所以肯定1下面有连续的h个点依次连成一条链。->用了h+1个点了
然后,考虑d这个约束。
会发现,形成d的这个路径,它一定是经过节点1比较好。
因为这条路径有两种可能->
1.经过了1节点
2.没有经过1节点,那么肯定是1的某个子树里面,但是如果它的子树里再来一条长度为d的路径,肯定没有比经过1来的好,因为如果在1的子树里面的话有增加树的高度h的风险。
为了降低这个超过h的风险,那么我们还是优先让这个路径经过节点1.
然后我们来构造这条长度为d的路径。因此还得在1节点的另外一个子树上创建d-h个节点。
同样接成一条链。
(但此时要判断这个d-h的高度会不会超过h,超过了的话那就无解了)
如果上面都没问题,那么高度h和d的要求就都满足。
但是别忘了还有一个节点个数的要求。
我们已经用了d+1个节点了。
还有n-d-1个节点没用。
这些点的话,可以这样,全都接在h号节点上(也即全都接在倒数第二层的节点上
(这里不是接成一条链了
这样就能做到既不会改变h,也不会改变d了。
但是有种情况要特判一下。
就是d = h =1的时候,这个时候只有两个节点,如果还有剩余的节点,那么就没办法再接了。因此也无解。
【代码】
#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define LL long long
using namespace std;
const int N = 1e4;
int n,d,h;
int main()
{
//freopen("D:\\rush.txt","r",stdin);
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> d >> h;
if (d-h>h){
cout<<-1<<endl;
return 0;
}
if (d==1){//1<=h<=d so h==d
if (n>=3){
cout<<-1<<endl;
return 0;
}
}
int cur = 1;
rep1(i,1,h){
cout<<cur<<' '<<cur+1<<endl;
cur++;
}
int now = 1;
rep1(i,1,d-h){
cout<<now<<' '<<cur+1<<endl;
now = ++cur;
}
rep1(i,1,n-d-1)
cout<<h<<' '<<++cur<<endl;
return 0;
}
【Codeforces 639B】Bear and Forgotten Tree 3的更多相关文章
- 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 ...
- 【codeforces 791D】 Bear and Tree Jumps
[题目链接]:http://codeforces.com/contest/791/problem/D [题意] 你可以从树上的节点一次最多走k条边. (称为跳一次); 树为无权树; 然后问你任意两点之 ...
- 【30.36%】【codeforces 740D】Alyona and a tree
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【32.89%】【codeforces 574D】Bear and Blocks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 764C】Timofey and a tree
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 514E】Darth Vader and Tree
[题目链接]:http://codeforces.com/problemset/problem/514/E [题意] 无限节点的树; 每个节点都有n个儿子节点; 且每个节点与其第i个节点的距离都是ai ...
- 【codeforces 791C】Bear and Different Names
[题目链接]:http://codeforces.com/contest/791/problem/C [题意] 给你n-k+1个限制 要求 a[i]..a[i]+k-1里面有相同的元素,或全都不同; ...
- 【codeforces 791B】Bear and Friendship Condition
[题目链接]:http://codeforces.com/contest/791/problem/B [题意] 给你m对朋友关系; 如果x-y是朋友,y-z是朋友 要求x-z也是朋友. 问你所给的图是 ...
- 【codeforces 791A】Bear and Big Brother
[题目链接]:http://codeforces.com/contest/791/problem/A [题意] 给你两个数字a和b; a每次乘3,b每次乘2 问你什么时候a第一次大于b [题解] 傻逼 ...
随机推荐
- Android实战简易教程-第四十一枪(显示倒计时的Button-适用于获取验证码)
近期在做获取验证码的功能.考虑到优良的用户体验,决定制作一个拥有倒计时提示的Button按钮,在网上查了一些资料,非常是简单的就能实现.我写了一个小Demo,大家能够应用到自己的项目中. 一.代码 1 ...
- Extjs显示图片
1.首先做一个容器 xtype : 'container', // 第2行 anchor : '100%', layout : 'column', items : [{ columnWidth : 0 ...
- 关于api-ms-win-crt-runtimel1-1-0.dll缺失的解决方案
关于api-ms-win-crt-runtimel1-1-0.dll缺失的解决方案 目录 关于api-ms-win-crt-runtimel1-1-0dll缺失的解决方案 目录 安装VC redite ...
- DCloud-JS-MUI-JS:utils.js
ylbtech-DCloud-JS:utils.js 1. 导航返回返回顶部 1. var oldBack = mui.back; mui.back = function () { mui.back ...
- nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter
转自:https://blog.csdn.net/licheng989/article/details/28929411 在Bean中有代码 public abstract Axe getAxe(); ...
- hdu3555Bomb(数位dp)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- Python 35 进程间的通信(IPC机制)、生产者消费者模型
一:进程间的通信(IPC):先进先出 管道:队列=管道+锁 from multiprocessing import Queue q=Queue(4) q.put(['first',],block=T ...
- 练习2 及pl/sql
Rownum 如果不是对主键排序是不会变得 -查询没有学分的学生信息 --SELECT * FROM z_student zs WHERE zs.code NOT IN (SELECT DISTINC ...
- [Swift]LeetCode1066. 校园自行车分配 II | Campus Bikes II
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 《CSS Mastery》读书笔记(2)
第二章 目标的样式 要用CSS样式化一个HTML元素,必须要定位一个元素, CSS的选择器就是这样的手段. 这章中,你要学到的 • Common selectors 普通选择器 • Advanc ...