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;
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章