HDU 6313 Hack It(数论构造)

Hack It

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

题意:让你构造一个n*n(n<=2000)的01矩阵,其中1的数量不少于85000,而且没有任意一个子矩阵四个角都是1。

思路:数论构造:

当我们取质数5时,  1的位置 在 j 上 依次 + 0,1,2,3,4,5......   mod 5 的 意义下

+0 : 10000 10000 10000 10000 10000

+1 : 10000 01000 00100 00010 00001

+2 : 10000 00100 00001 01000 00010

+3 : 10000 00010 01000 00001 00100

+4 : 10000 00001 00010 00100 01000

以上是第一个块

+0:01000 01000 01000 01000 01000(第一个块1都向右移,mod5)

+1 : 01000 00100 00010 00001 10000

+2 : 01000 00010 01000 00001 00100

+3 : 01000 00001 00010 00100 01000

+4 : 01000 10000 00001 00010 00100

...直到构造出25*25的矩阵。因此我们用质数5构造出的是5*5 * 5*5的矩阵。(为的是构造不会重复, 所以使用质数。)

而sqrt(2000) 最接近的质数是47。因此用47构造。这样构造出来的2000*2000的矩阵1的数量是85105,刚好够(出题人就是想卡这个)

代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int gg[3333][3333];
int main()
{
    int p=47;
    for(int i=0;i<p;i++)
    for(int j=0;j<p;j++)
    for(int k=0;k<p;k++)
    gg[i*p+j][k*p+(j*k+i)%p]=1;
    puts("2000");
    for(int i=0;i<2000;++i,puts(""))
        for(int j=0;j<2000;++j)
            printf("%d",gg[i][j]);
            return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值