2018 Multi-University Training Contest 2-----hdu6313Hack It【构造题】

                 Hack It

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 668    Accepted Submission(s): 216
Special Judge

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.

 题意:

这道题很有意思,是一道构造题,在我做不出其他题的时候全程都在推这道题的规律。

看了杜老师的构造真的觉得很牛逼!!QAQ

打印数字n和一个n*n的矩阵,里面只有1和0,里面的1不可以四角构成一个矩形。

而且1的个数要不少于85000个,n的范围为1到2000。

思路:

用分块的思想,分成m*m个正方形,子正方形的边长也为m,且m必须为质数。

例如以m为5作为例子

为了打出2000*2000的矩阵

因此推出最小且适合的质数为47。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int mapp[47*47+2][47*47+2];
int main() {
	memset(mapp, 0, sizeof(mapp));
	int n = 47;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				mapp[i*n+j][k*n+((k*j)+i)%n] = 1;
			}
		}
	}
	printf("2000\n");
	for(int i = 0; i < 2000; i++){
		for(int j = 0; j < 2000; j++){
			printf("%d",mapp[i][j]);
		}
		printf("\n");
	}
	return 0;
}

 

全部评论

相关推荐

码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
白火同学:只是实习的话,你这份简历应该也差不多了。真要优化的话,因为面实习的话,没有开发经验,面试更重视技术栈水平。 1、重视JavaSE的基础吧,集合、泛型算是比较基础的基础,多线程、反射、JVM内存模型才是基础; 2、技术栈写到具体的点,比如Elasticsearch的使用写到某个点,限制面试官自由发挥,防止问了相关问题最后又答不上,如果真没把握建议不写,降低面试官的心理预期; 3、技术栈不要重复,比如技术栈第二条和第八条可以合并改为“熟悉Redis中间件,包括基本数据结构、缓存策略、持久化机制,了解缓存三剑客及其解决方案,并有相关项目经验。”; 4、项目指标量化,比如“达到xx秒的响应速度”(不过这个就有点偏校招社招的要求了,实习简历不写也无伤大雅)。
点赞 评论 收藏
分享
看到这个内容真是闹麻了。。。。。。现在有了AI以后很多人面试都会作弊吗?&nbsp;那对老老实实面试的人岂不是不公平....
程序员牛肉:公平那是对小孩子讲的童话故事,成年人的世界只有能不能接受失败的后果。 你要是能接受面试作弊被发现之后多家公司联合永久拉黑的后果,你就搞。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务