output
standard output
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly kcycles of length 3.
A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge.
John has been painting for long, but he has not been a success. Help him find such graph. Note that the number of vertices there shouldn't exceed 100, or else John will have problems painting it.
Input
A single line contains an integer k (1 ≤ k ≤ 105) — the number of cycles of length 3 in the required graph.
Output
In the first line print integer n (3 ≤ n ≤ 100) — the number of vertices in the found graph. In each of next n lines print n characters "0" and "1": the i-th character of the j-th line should equal "0", if vertices i and j do not have an edge between them, otherwise it should equal "1". Note that as the required graph is undirected, the i-th character of the j-th line must equal the j-th character of the i-th line. The graph shouldn't contain self-loops, so the i-th character of the i-th line must equal "0" for all i.
Examples
input
Copy
1
output
Copy
3 011 101 110
input
Copy
10
output
Copy
5 01111 10111 11011 11101 11110
题意是让你找k个 连起来的三个点。矩阵的行列a[i][j]==1代表第i个点和第j个点之间有一条边连起来0代表没连起来,那么由于和点的顺序没有关系那我们就按顺序添加就可以了。
假设我们在添加第i个点那么前i-1个点肯定已经两两相互连接了(要不然就还在上一个点 )然后我们开始连接(即增加边数)当我们增加第一条边的时候它是构不成三角形的,添加第二条构成了一个添加第三条边多构成了两个所以每当我门加第K条边那么三角形就会多K-1个。
#include <iostream>
#include<cmath>
#include<string.h>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<set>
using namespace std;
long long inf=1e9+7;
struct mov
{
int minn,maxx;
} d[1000000];
int n,k,t,m;
int a[1000][1000];
int main()
{
int n;
memset(a,0,sizeof(a));
cin>>n;
int v=1;
while(n>0)
{
for(int i=0; i<=n&&i<=v; i++)
{
if(i==v)
continue;
a[i][v]=a[v][i]=1;
n-=i;
}
v++;
/*for(int i=0; i<v; i++)//可以将注释去掉看一下中间过程
{
for(int j=0; j<v; j++)
{
cout<<a[i][j];
}
cout<<endl;
}
cout<<endl;*/
}
cout<<v<<endl;
for(int i=0; i<v; i++)
{
for(int j=0; j<v; j++)
{
cout<<a[i][j];
}
cout<<endl;
}
}