【链接】 我是链接,点我呀:)

【题意】

【题解】

首先,因为高度是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的更多相关文章

  1. 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 ...

  2. 【codeforces 791D】 Bear and Tree Jumps

    [题目链接]:http://codeforces.com/contest/791/problem/D [题意] 你可以从树上的节点一次最多走k条边. (称为跳一次); 树为无权树; 然后问你任意两点之 ...

  3. 【30.36%】【codeforces 740D】Alyona and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【32.89%】【codeforces 574D】Bear and Blocks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 764C】Timofey and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 514E】Darth Vader and Tree

    [题目链接]:http://codeforces.com/problemset/problem/514/E [题意] 无限节点的树; 每个节点都有n个儿子节点; 且每个节点与其第i个节点的距离都是ai ...

  7. 【codeforces 791C】Bear and Different Names

    [题目链接]:http://codeforces.com/contest/791/problem/C [题意] 给你n-k+1个限制 要求 a[i]..a[i]+k-1里面有相同的元素,或全都不同; ...

  8. 【codeforces 791B】Bear and Friendship Condition

    [题目链接]:http://codeforces.com/contest/791/problem/B [题意] 给你m对朋友关系; 如果x-y是朋友,y-z是朋友 要求x-z也是朋友. 问你所给的图是 ...

  9. 【codeforces 791A】Bear and Big Brother

    [题目链接]:http://codeforces.com/contest/791/problem/A [题意] 给你两个数字a和b; a每次乘3,b每次乘2 问你什么时候a第一次大于b [题解] 傻逼 ...

随机推荐

  1. hdu 4932 Miaomiao&#39;s Geometry(暴力枚举)

    pid=4932">Miaomiao's Geometry                                                               ...

  2. oc26--Property,省略setget的声明

    // // Person.h #import <Foundation/Foundation.h> @interface Person : NSObject { int _age; } /* ...

  3. string 类型的翻转

    #include <string>#include <iostream>#include <stack> int main() { std::string str= ...

  4. 803E

    dp dp[i][j]表示到了i赢和输的差为j 如果这位是?向dp[i-1][j-1],dp[i-1][j],dp[i-1][j+1]转移,如果是W向dp[i-1][j-1]转移,如果是L向dp[i- ...

  5. ECharts-热力图实例

    1.引入echarts.js 2.页面js代码 //用ajax获取所需要的json数据 $.get("../../../mall/queryPageWtSrPost.do", { ...

  6. .sh文件 编写格式

    http://blog.sina.com.cn/s/blog_54f82cc201010hfz.html 介绍: 1 开头 程序必须以下面的行开始(必须方在文件的第一行): #!/bin/sh 符号# ...

  7. [BZOJ1041]圆上的整点

    嗯... 自己看视频讲解? >Click Here< #include<cstdio> #include<queue> #include<iostream&g ...

  8. windows服务安装错误 在‘安装’过程发生异常:System.ComponentModel.Win32Exception:系统正在关机

    今天安装windows服务的时候先是在本地安装测试通过,但是一到服务器就一直安装失败 在‘安装’过程发生异常:System.ComponentModel.Win32Exception:系统正在关机 然 ...

  9. sql--Truncate Table

    Truncate Table(截断表) 有时候需要清除一个表中的所有资料.要达到者个目的,一种方式是DROP TABLE 指令.不过这样整个表格就消失,而无法再被用了. 另一种方式是Delete不带w ...

  10. windows下查看端口进程占用情况

    引用:http://jingyan.baidu.com/article/3c48dd34491d47e10be358b8.html 我们在启动应用的时候经常发现我们需要使用的端口被别的程序占用,但是我 ...