HDU 6313 Hack It(思维构造)

Hack It

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 495    Accepted Submission(s): 148
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.

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)

 想了好久的构造题,赛后听题解终于听明白了orz

扫描二维码关注公众号,回复: 2531217 查看本文章

把2000*2000分成几个块来搞,具体分成多少个呢,有说43有说47的,又听说43不行,就用47,一定要用个素数,47*47=2209>2000,所以将2000*2000的矩阵分成47行,47列

然后以25为例,将25*25的大矩阵分为5*5的小矩阵(这里只列出前5行前25列,也就是分块后的矩阵中的第一行的全部)

10000 10000 10000 10000 10000
10000 01000 00100 00010 00001
10000 00100 00001 01000 00010
10000 00010 01000 00001 00100
10000 00001 00010 00100 01000

分别对上一行的1的位置+1取模,就可以得到了

也不知道理解的是不是对的==

#include<iostream>
using namespace std;
const int n=47;
const int maxn=3010;
int map[maxn][maxn];
int main()
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				map[i*n+j][k*n+(j*k+i)%n]=1;
			}
		}
	}
	cout<<2000<<endl;
	for(int i=0;i<2000;i++)
	{
		for(int j=0;j<2000;j++)
		{
			cout<<map[i][j];
		}
		cout<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37943488/article/details/81215000
今日推荐