VK Cup 2016 - Round 1 (Div. 2 Edition)-C - Bear and Forgotten Tree 3-构造

18 篇文章 0 订阅

http://codeforces.com/contest/658/problem/C


卧槽。。真是大脑缺氧了。。。这么简单的一个构造题。。。

给你n,d,h构造出一个n个节点 直径为d高为h的树(根为1)

无法构造输出-1;

直接特判【2*h<d】输出-1

还有一个情况就是【h==d的时候,直径是一条链......如果节点n>=d+1的话,那么多出来的节点如果接在根1就会导致直径增加,所以可以接到点2去(这样不会导致直径增加,高度也不变)(注意当d=1的时候还是会导致直径增加,必然-1)】


其余情况直接 先构造一个1-2-3-(h+1)的高,然后补齐1- (h+2)-(h+3)----(d)

然后剩下的点全部和根1直接相连即可。。。。 


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001; 
__int64 min(__int64 a,__int64 b)
{return a<b?a:b;} 
__int64 max(__int64 a,__int64 b)
{return a>b?a:b;}

struct node
{
	int x,y;
	node(){}
	node(int a,int b){x=a,y=b;}
};
node tm[100005];
int cun=0;
int vis[100005];
int main() 
{ 
	int i,j;
	int n,d,h;
	scanf("%d%d%d",&n,&d,&h);
	if (h==d)
	{ 
			if (n-1>h)
			{
				
				if (h==1) {printf("-1\n");return 0;}
				int ok=1;
				for (i=1;i<=h;i++)
				{	
					printf("%d %d\n",ok,ok+1);
				ok++;
				}
				ok++;
				for (i=h+1;i<n;i++)
				{
					printf("%d %d\n",2,ok);ok++;
				} 
			return 0;
			} 
	}
	if (d<h||2*h<d)
	{
		printf("-1\n");
		return 0;
	}
	int ok=1;
	for (i=1;i<=h;i++)
	{
		//printf("%d  %d\n",ok,ok+1);
		tm[++cun]=node(ok,ok+1); 
		ok++;
	}
	ok++;
	int need=d-h; 
	int flag=0;
	if (need)
	{
		for (i=1;i<=need;i++)
		{
			if (i==1)
				tm[++cun]=node(1,ok);
			//printf("1 %d\n",ok);
			else
			{ 
				//printf("%d %d\n",ok,ok+1);
				tm[++cun]=node(ok,ok+1);
				ok++;
			}
			
		} 
		ok++;
	}
	int res=n-d-1;
	for (i=1;i<=res;i++)
	{
		tm[++cun]=node(1,ok);
		//printf("1 %d\n",ok);
		ok++;
	}
	if (cun!=n-1)
	{
		printf("-1\n");
		return 0;
	} 
	 
	
	for (i=1;i<=cun;i++)
	{
		printf("%d %d\n",tm[i].x,tm[i].y);
	}
	
	
	return 0;
	
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值