Codeforces 232A - Cycles (构造 + 思维)

题目链接:

232A - Cycles(点击打开)

题意:

要构成一个存在 \(k\) 个三元环的图,需要多少个点,输出顶点数 \(n\),并输出图。

题解:

题目中的任何图都可以用 \(90\)~ \(100\)个顶点构造完成。

Proof that \(100\) vertices are always enough for the given restrictions on \(n\).

- For some \(p\) after first \(p\) iterations we will have a complete graph of \(p\) vertices.

- Now we have exactly \(C(p, 3)\) triangles. Consider \(p\) such that \(C(p, 3)  ≤ k\) and \(C(p, 3)\) is maximal.

- For the given restrictions \(p ≤ 85\).

- From this moment, if we add \(u\) from some vertex, we increase the total number of 3-cycles on \(C(u, 2).\)

- So we have to present a small number that is less than \(C(85, 3)\) as sum of \(C(i, 2)\).

The first number we subtruct will differ \(C(85, 1)\) on some value not greater than \(C(85, 1) = 85\), because \(C(n, k) - C(n - 1, k) = C(n - 1, k - 1)\).

- The second number we subtruct will differ the number we have on some value not greater than \(C(14, 1) = 14.\)

- and so on.

- For every \(k\) it's enough to use not more that \(90\) vertices.

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int g[123][123];
int main()
{
    int k;
    cin>>k;//要求的三元环个数 
    for(int i=0;i<90;i++)//依次增加顶点 
    {
        int sum = 0;//三元环个数 
        for(int j = 0; j < i && sum <= k;j++)
        {
            k-=sum;
            sum++;
            g[i][j] = g[j][i] = 1;
        }
     }
    cout<<90<<endl;
    for(int i=0;i<90;i++)
    {
        for(int j=0;j<90;j++)
        {
            int ans = g[i][j] ? 1:0;
            cout<<ans;
        }
        cout<<endl;
    }
    return 0;
}

转载于:https://www.cnblogs.com/LzyRapx/p/7652988.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值