C语言的程序算法伪代码怎么变成实现的程序的方式,具体的思路

Problem Description
Tonyfang is a clever student. The teacher is teaching he and other students "bao'sou".
The teacher drew an n*n matrix with zero or one filled in every grid, he wanted to judge if there is a rectangle with 1 filled in each of 4 corners.
He wrote the following pseudocode and claim it runs in O(n2):

let count be a 2d array filled with 0s
iterate through all 1s in the matrix:
suppose this 1 lies in grid(x,y)
iterate every row r:
if grid(r,y)=1:
++count[min(r,x)][max(r,x)]
if count[min(r,x)][max(r,x)]>1:
claim there is a rectangle satisfying the condition
claim there isn't any rectangle satisfying the condition

As a clever student, Tonyfang found the complexity is obviously wrong. But he is too lazy to generate datas, so now it's your turn.
Please hack the above code with an n*n matrix filled with zero or one without any rectangle with 1 filled in all 4 corners.
Your constructed matrix should satisfy 1≤n≤2000 and number of 1s not less than 85000.

Input
Nothing.

Output
The first line should be one positive integer n where 1≤n≤2000.

n lines following, each line contains only a string of length n consisted of zero and one.

Sample Input
(nothing here)

Sample Output
3
010
000
000
(obviously it's not a correct output, it's just used for showing output format)

将算法伪代码转换成实现的程序通常需要遵循以下步骤:

  1. 审阅算法伪代码并确保对其理解透彻。你需要理解算法伪代码中使用的各种数据结构、循环、条件语句以及其他功能。

  2. 进行设计。根据算法的目标和需求,选择合适的开发环境并进行程序设计。设计时应当考虑如何将算法的核心部分转换成代码,并确定代码的基本结构以及所需的数据结构。

  3. 编写代码。使用设计好的程序框架,将算法伪代码逐行转换成实际的编程语言代码。在编写代码时应注意代码规范和可读性,尽可能注释每一个重要的语句和功能,这样可以让代码更加容易理解和维护。

  4. 调试程序。编写程序后需要进行严格的测试和调试,以确保程序的正确性和鲁棒性。测试时应尽可能模拟各种情况和异常情况,如错误输入、边界条件等。

  5. 优化程序。如果程序在测试中出现性能问题,你需要进一步优化程序以提高其效率和降低资源使用率。常见的优化手段包括使用更合适的数据结构、减少函数调用次数、使用位运算等技巧等。