2018杭电多校第二场补题 1005 Hack It 数论

Hack It

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

emmmmmmm

本来以为是找规律,题解下来后被队友仔细研读后发现是数论,可我跟数论八字不合啊~~~于是,就被带飞了

orz成则穿裙

AC代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=47*47;
const int P=47;
int a[maxn+10][maxn+10];
int main()
{
    int k,b,y;
    cout<<"2000\n";
    for(int x=0;x<maxn;x++)
    {
        k=x/P;
        b=x%P;
        for(int i=0;i<P;i++)
        {
            y=i*P+(k*i+b)%P;
            a[x][y]=1;
        }
    }
    long long ans=0;
    for(int i=0;i<2000;i++)
    {
        for(int j=0;j<2000;j++)cout<<a[i][j];
        cout<<'\n';
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/AC_hunter/article/details/81214033