P2031 "poetize9" elevator Port

Source: Internet
Author: User
3056: Elevator port time limit: 2 sec memory limit: 128 MB
Submit: 43 solved: 42
[Submit] [Status] Description

Some explorer team up to explore the mysterious tower of Nescafe. After some twists and turns, the expedition team finally broke through the tower and came to the main hall of the tower of Nescafe. The four flood guards and the Holy Lord of the tower that the expedition team members wanted to visit all lived on the top of the tower, so they quickly rushed to the elevator exit on the side of the main hall. However, because the Nescafe tower is an annual place to seal and open the "Nescafe Cup", it is naturally not allowed to allow outsiders to break in at will. Therefore, to take a lift ladder, the team members must crack the password for enabling the lift power.

The password disk of the elevator is a square consisting of n * n squares (N is an even number), and the square in column J of line I won the number (I-1) * n + J, on the top of the cipher disk, There is a photo block consisting of n x n squares. If the N * n/4 grids on the fenders are removed and the number of N * n/4 grids is counted from small to large; then rotate the fenders 90 °, 180 °, and 270 ° clockwise, and write down the N * n/4 number each time. In this way, the N * n number is obtained. If the N * n number is exactly 1 ~ N * n is an arrangement, so we call this piece of fenders that dig N * n/4 grids to "precisely overwrite" the password disk. We may use a matrix of N * n 01 to represent the fenders. The extracted lattice is 1 and the undug lattice is 0. The fenders shown in can be expressed:

0000
0000
1101
0001
Defines that a is smaller than B, when and only when the Lexicographic Order of the 01 matrix corresponding to a is smaller than that of the 01 matrix corresponding to B (I .e: A location (x, y) exists in the 01 matrix corresponding to a and B, so that all the numbers in the front X-1 row of matrix A and B are the same as the first Y-1 number in the row X, the number in column Y of row X in a is 0, and the number in column Y of row X in B is 1 ).
Now there is a digital K on the wall of the elevator lift port, and the expedition team must quickly create a small K block that "precisely covers" the password disk, it is used to obtain N * n numbers on the password disk as the password to enable the elevator power.


Input

A row contains two positive integers N and K.

Output

Output the 01 matrix corresponding to the qualified fenders.

Sample input4 15

Sample output0000
0000
1101
0001

Hint



Test Point No. n k

#1 = 2 <= 10

#2 = 2 <= 10 ^ 3

#3 = 4 <= 10

#4 = 4 <= 10 ^ 9

#5 = 6 <= 10

#6 = 6 <= 10 ^ 18

#7 = 8 <= 10

#8 = 8 <= 10 ^ 18

#9 = 10 <= 10 ^ 18

#10 = 10 <= 10 ^ 18

Data can be resolved.

Source

Poetize10

Question:

At first, I saw the question because it was a God question.

After reading the question, I felt like I was good at sb...

Because each point can be rotated to a certain extent, we divide any point that can be rotated into N * n/4 groups, then, each and only one of these groups can satisfy the question...

Then consider the k-th small solution, just like finding rank in treap... Tat

There is another small problem: (x, y) What is the coordinate after 90 degrees of rotation around the center? The answer is (n-y + 1, x)

Also note that 1 <50 will pop up!

Code:

  1 #include<cstdio>  2   3 #include<cstdlib>  4   5 #include<cmath>  6   7 #include<cstring>  8   9 #include<algorithm> 10  11 #include<iostream> 12  13 #include<vector> 14  15 #include<map> 16  17 #include<set> 18  19 #include<queue> 20  21 #include<string> 22  23 #define inf 1000000000 24  25 #define maxn 500+100 26  27 #define maxm 500+100 28  29 #define eps 1e-10 30  31 #define ll long long 32  33 #define pa pair<int,int> 34  35 #define for0(i,n) for(int i=0;i<=(n);i++) 36  37 #define for1(i,n) for(int i=1;i<=(n);i++) 38  39 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 40  41 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 42  43 #define mod 1000000007 44  45 using namespace std; 46  47 inline int read() 48  49 { 50  51     int x=0,f=1;char ch=getchar(); 52  53     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 54  55     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();} 56  57     return x*f; 58  59 } 60 int c[20][20],v[500],ans[20][20],n; 61 ll  m,t,f[500]; 62 ll calc() 63 { 64     ll ret=1; 65     for1(i,t)if(!v[i]&&ret<2e18)ret*=f[i]; 66     return ret; 67 } 68  69 int main() 70  71 { 72  73     freopen("input.txt","r",stdin); 74  75     freopen("output.txt","w",stdout); 76  77     cin>>n>>m; 78     for1(i,n) 79      for1(j,n) 80       if(!c[i][j]) 81       {   82         f[++t]=4; 83           for(int k=1,x=i,y=j;k<=4;k++) 84             swap(x,y),x=n-x+1,c[x][y]=t; 85       } 86     m=((ll)1<<(2*t))-m+1;   87     for1(i,n) 88      for1(j,n) 89        if(!v[c[i][j]]) 90        { 91            v[c[i][j]]=1; 92            ll tmp=calc(); 93            if(tmp>=m)ans[i][j]=1; 94             else m-=tmp,f[c[i][j]]--,v[c[i][j]]=0; 95        } 96     for1(i,n) 97     { 98      for1(j,n)if(ans[i][j])printf("1");else printf("0"); 99      printf("\n");100     }101 102     return 0;103 104 }
View code

 

 

P2031 "poetize9" elevator Port

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.