首页 > 代码库 > codeforces 639B Bear and Forgotten Tree 3

codeforces 639B Bear and Forgotten Tree 3

细节不少的构造题。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,d,h,p=1,ret=1;int main(){    scanf("%d%d%d",&n,&d,&h);    if (2*h<d) {printf("-1\n");return 0;}    if (d==1)     {        if (n==2) printf("1 2\n");        else printf("-1\n");        return 0;    }    for (int i=1;i<=h;i++)        printf("%d %d\n",i,i+1);    p=h+2;    for (int i=1;i<=d-h;i++)    {        printf("%d %d\n",ret,p);        ret=p;p++;    }    if (p!=n+1)    {        if (d!=h)        {            for (int i=p;i<=n;i++)                printf("1 %d\n",i);        }        else        {            for (int i=p;i<=n;i++)                printf("2 %d\n",i);        }    }    return 0;}

 

codeforces 639B Bear and Forgotten Tree 3