首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【CodeForces】233C - Cycles(贪心)

【CodeForces】233C - Cycles(贪心)

作者头像
FishWang
发布2025-08-26 20:45:37
发布2025-08-26 20:45:37
11700
代码可运行
举报
运行总次数:0
代码可运行

题目链接:点击打开链接

C. Cycles

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

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

代码语言:javascript
代码运行次数:0
运行
复制
1

output

代码语言:javascript
代码运行次数:0
运行
复制
3
011
101
110

input

代码语言:javascript
代码运行次数:0
运行
复制
10

output

代码语言:javascript
代码运行次数:0
运行
复制
5
01111
10111
11011
11101
11110

每添加一条线,贡献多少个环要算好,然后就不难了。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
int mapp[111][111];
int main()
{
	int n;
	scanf ("%d",&n);
	int l = 2;
	int ant = 0;
	mapp[1][2] = mapp[2][1] = 1;
	for (int i = 3 ; i <= 100 ; i++)
	{
		l = max(l,i);
		mapp[i][1] = mapp[1][i] = 1;
		for (int j = 2 ; j < i ; j++)
		{
			mapp[i][j] = mapp[j][i] = 1;
			ant += j-1;
			if (ant == n)
				break;
			else if (ant > n)
			{
				ant -= j-1;
				mapp[i][j] = mapp[j][i] = 0;
				break;
			}
		}
		if (ant == n)
			break;
	}
	printf ("%d\n",l);
	for (int i = 1 ; i <= l ; i++)
	{
		for (int j = 1 ; j < l ; j++)
			printf ("%d",mapp[i][j]);
		printf ("%d\n",mapp[i][l]);
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档