题目链接:
题意:
要构成一个存在 \(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;
}