codeforces 233 csycles

本文探讨如何构造一个特定数量的三角形循环的无向图,通过逐步添加节点并建立连接来形成所需数量的三角形循环,确保每个三角形循环由三个不同的顶点组成,且任意两点间存在边。

题目

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 ab 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;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值