2018 牛客多校第七场 E Counting 4-Cliques (找规律)

https://www.nowcoder.com/acm/contest/145/E

题意:构造一个<=75个点的图,使得大小为4的团恰有k个。(k<=1e6)

思路:

可以发现每种都能够由这个C(t,4)+C(a,3)+C(b,3)+C(c,3)+C(d,3)+C(e,3)组成,只要先找到最大的t,

然后暴力跑四重循环,找到a,b,c,d,e,就可以了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+10;
int mp[maxn];
int C4(int n)
{
    return n*(n-1)*(n-2)*(n-3)/(1*2*3*4);
}
int C3(int n)
{
    return n*(n-1)*(n-2)/(1*2*3);
}
void init()
{
    memset(mp,-1,sizeof(mp));
    for(int i=1;i<=70;i++)
    {
        mp[C3(i)]=i;
    }
}
int main()
{
    init();
    int n;
    scanf("%d",&n);
    int t=4;
    int m=70;
    while((t+1)<=m&&C4(t+1)<=n)
    {
        t++;
    }
    n-=C4(t);
    m=min(m,t);
    int a,b,c,d,e=-1;
    for(a=2;a<=m;a++)
    {
        for(b=2;b<=m;b++)
        {
            for(c=2;c<=m;c++)
            {
                for(d=2;d<=m;d++)
                {
                    int cnt=C3(a)+C3(b)+C3(c)+C3(d);
                    if(cnt<=n&&mp[n-cnt]>=0&&mp[n-cnt]<=m)
                    {
                        e=mp[n-cnt];
                        break;
                    }
                }
                if(e!=-1)break;
            }
            if(e!=-1)break;
        }
        if(e!=-1)break;
    }
    printf("%d %d\n",t+5,t*(t-1)/2+a+b+c+d+e);
    for(int i=1;i<=t;i++)
    {
        for(int j=i+1;j<=t;j++)
        {
            printf("%d %d\n",i,j);
        }
    }
    for(int j=1;j<=a;j++)
    {
        printf("%d %d\n",t+1,j);
    }
    for(int j=1;j<=b;j++)
    {
        printf("%d %d\n",t+2,j);
    }
    for(int j=1;j<=c;j++)
    {
        printf("%d %d\n",t+3,j);
    }
    for(int j=1;j<=d;j++)
    {
        printf("%d %d\n",t+4,j);
    }
    for(int j=1;j<=e;j++)
    {
        printf("%d %d\n",t+5,j);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/imzxww/article/details/81565594