http://codeforces.com/problemset/problem/639/B Bear and Forgotten Tree 3

很容易想到的一个构造法,从1开始往左建到h高,然后在h - 1的位置不断增加结点,直到剩下d - h个结点,然后放在1的右边不断往下建立,但要注意一个特殊情况,即n>2时,d=h=1时,其他的-1的情况显然时h > 2 * d的时候。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <list>
#include <stack>
#include <cstring>
#include <queue>
#include <map>
#include <string>
using namespace std;
#define MAX 205
#define ll long long
#define INF 0x3f3f3f3f
#define mod 1000000007
int n, d, h;
int main()
{
    freopen("a.txt", "r", stdin);
    freopen("b.txt", "w", stdout);
    cin >> n >> d >> h;
    if (d > h * 2 || (n > 2 && d == 1 && h == 1)) {
        puts("-1");
        return 0;
    }
    for (int i = 2; i <= h + 1; ++i) {
        printf("%d %d\n", i - 1, i);
    }
    for (int i = h + 2; i <= n - (d - h); ++i) {
        printf("%d %d\n", h, i);
    }
    int s = 1;
    for (int i = n - (d - h) + 1; i <= n; ++i) {
        printf("%d %d\n", s, i);
        s = i;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值