2018暑假多校赛【第二场】【构造】-Hack It-YZHHHHHHH

11 篇文章 0 订阅
10 篇文章 0 订阅

Hack It

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


题意:

特殊判断

1、输出一个n*n的矩阵

2、该矩阵被 0 和 1 填满

3、“1” 不能形成矩形且矩阵内要有不少于85000个1

构造矩阵

5*5矩阵的前5行

对j进行

j+0 10000 10000 10000 10000 10000
j+1 10000 01000 00100 00010 00001
j+2 10000 00100 00001 01000 00010
j+3 10000 00010 01000 00001 00100
j+4 10000 00001 00010 00100 01000
下面的20行将1依次向右移一位。

需要注意的是:mod要选择质数,46*46=2116,47*47=2209.

代码:

#include <stdio.h>

int s = 2000;	//整个矩阵的大小 
int mod = 47;	//mod需选择质数,防止重复 
int mapp[3000][3000];
int main(){
	//构造矩阵 
	for (int i = 0; i < mod; i++){
		for (int j = 0; j < mod; j++){
			for (int k = 0; k < mod ; k++){
				mapp[i*mod+j][k*mod + (j*k+i) % mod] = 1;
			}
		}
	}
	//输出矩阵 
	printf("2000\n");
	for (int i = 0; i < 5; i++){
		for (int j = 0; j < s; j++){
			printf("%d",mapp[i][j]);
			//if (j % 5 == 4) printf(" ");
		}
		//if (i % 5 == 4) printf("\n");
		printf("\n");
	}
}

 

吐槽一下题目。。。

正道题目只有红色框的两句话有用。。。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值