HDU 6313 Hack It (循环加群构造)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6313

Hack It

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

 

 

Source

2018 Multi-University Training Contest 2

 2000*2000看成某个质数的四次方 也就是47

为什么是四次方  因为可以把整个矩阵看成47*47个47*47的小方阵

小方阵里就是通常加法意义下模47的循环加群

如果模的是合数循环群表上会有某几行是重复的结果 数论书上有。。

枚举加值和起始位置就可构造出47*47个小方阵

听视频讲解之后反应过来然后反思自己为什么这么菜。。

 

理解是个循环加群之后就很好写代码了。。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#define max_ 47
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;
int main()
{
    //freopen("data.txt","w",stdout);
    cout <<"2000" <<endl;
    for(int i=1;i<=47;i++)//cong i kai shi
    {
        for(int j=1;j<=47;j++)//bu chang
        {
            int mid=i;
            int cnt=0;
            for(int k=1;k<=47;k++)
            {
                mid=(mid+j)%47;
                for(int l=0;l<47;l++)
                {
                    if(l==mid)
                        cout << "1";
                    else
                        cout <<"0";
                    cnt++;
                    if(cnt==2000)
                        break;
                }
                if(cnt==2000)
                    break;
            }
            cout << endl;
        }
        cout <<endl;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值