牛客网暑期ACM多校训练营(第七场)E:Counting 4-Cliques(思维)

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

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld
题目描述
You love doing graph theory problems. You’ve recently stumbled upon a classical problem : Count the number of 4-cliques in an undirected graph.

Given an undirected simple graph G, a 4-clique of G is a set of 4 nodes such that all pairs of nodes in this set are directly connected by an edge.

This task would be too easy for you, wouldn’t it? Thus, your task here is to find an undirected simple graph G with exactly k 4-cliques. Can you solve this task?

输入描述:
The first line of input contains a single integer k(1k106) k ( 1 ≤ k ≤ 10 6 ) .
输出描述:
On the first line, output two space-separated integers, n,m(1n75,1mn(n1)/2). n , m ( 1 ≤ n ≤ 75 , 1 ≤ m ≤ n ∗ ( n − 1 ) / 2 ) . On the next m lines, output two space-separated integers denoting an edge of the graph u,v(1u,vn) u , v ( 1 ≤ u , v ≤ n ) , where u and v are the endpoints of the edge.

Your graph must not contain any self-loops or multiple edges between the same pair of nodes. Any graph that has exactly k 4-cliques and satisfies the constraints will be accepted. It can be proven that a solution always exist under the given constraints.
示例1
输入
1
输出
4 6
1 2
1 3
1 4
2 3
2 4
4 3
说明
In the sample, the whole graph is a 4-clique.

题解:构造一个大小为 t t 的完全图,和a,b,c,d,e五个点。
a,b,c,d,e a , b , c , d , e 五个点之间没有边,他们只会向 t t 个点连边。
• 如果连了x个,构成 C3x C x 3 个大小为4的团。
• 找到最大的 t t ,枚举abcd计算 e e
• 也可以直接背包,并且记录方案。
• 时间复杂度704或者是背包复杂度

#include<bits/stdc++.h>
using namespace std;
const int MAX=1e6+10;
const int MOD=1e9+7;
typedef long long ll;
ll c[100][5];
ll v[MAX];
void init()
{
    c[3][3]=c[4][4]=1;
    for(int i=5;i<=80;i++)c[i][4]=c[i-1][4]*i/(i-4);
    for(int i=4;i<=80;i++)c[i][3]=c[i-1][3]*i/(i-3);
    for(int i=3;i<=80;i++)v[c[i][3]]=i;
}
int main()
{
    init();
    int cnt;
    cin>>cnt;
    int n;
    for(int i=1;i<=70&&c[i][4]<=cnt;i++)n=i;
    cnt-=c[n][4];
    for(int i=0;i<=n;i++)
    for(int j=0;j<=i;j++)
    for(int k=0;k<=j;k++)
    for(int h=0;h<=k;h++)
    {
        int res=cnt-(c[i][3]+c[j][3]+c[k][3]+c[h][3]);
        if(res<0)break;
        if(v[res]>n||(res&&v[res]==0))continue;
        printf("%d %d\n",n+(i>0)+(j>0)+(k>0)+(h>0)+(v[res]>0),n*(n-1)/2+i+j+k+h+v[res]);
        for(int x=1;x<=n;x++)
        for(int y=x+1;y<=n;y++)printf("%d %d\n",x,y);
        if(i)n++;for(int x=1;x<=i;x++)printf("%d %d\n",n,x);
        if(j)n++;for(int x=1;x<=j;x++)printf("%d %d\n",n,x);
        if(k)n++;for(int x=1;x<=k;x++)printf("%d %d\n",n,x);
        if(h)n++;for(int x=1;x<=h;x++)printf("%d %d\n",n,x);
        if(v[res])n++;for(int x=1;x<=v[res];x++)printf("%d %d\n",n,x);
        return 0;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值