2020 cattle off winter training camp algorithm base 3 [B] - Taurus II DRB maze

Topic links: https://ac.nowcoder.com/acm/contest/3004/B

First wrote this construction problem, thought out QAQ time of the game. Constructor is very clever. Figure solution to a problem first official pull over.

 

FIG explain this: the initial state is shown, wholly fill blank areas D (except the last row), fill the whole last line R.

Counts from 0, i th column of the i-th row (i.e. diagonal elements) value 2 i (i.e. 1 << i). 2 n- all in multiples of 2 by adding various combinations to form one may be 2 n-+. 1 all numbers between. To facilitate understanding of the following modifications to the FIG.

 

 

Res grid to the corresponding required final answer, only needs to determine which numbers res is constituted and then the blue region of the corresponding row R B can be changed. This will be a value corresponding to the current column pass downwardly until the last row.

Since the answer will then modulo 1e9 + 7, so we only need to compute 30 as << 1 30 = 1073741824, subscript 0 ~ 29.

The number of rows required for the purposes of line 32, because line 31 (subscript 30) requires line 30 (subscript 29) to select whether to process data. Line 32 (subscript 31) R - full answers to the last cell transmitted from left to right.

For determining which of the binary numbers and bit operations and can.

With code:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=55;
 4 char res[maxn][maxn];
 5 int main(){
 6     int n=32,m=30;
 7     int k;
 8     cin>>k;
 9     for(int i=0;i<30;i++){
10         res[0][i]='D';
11         res[30][i]='D';
12         res[31][i]='R';
13     }
14     res[0][0]='B';
15     res[30][29]='R';
16     for(int i=1;i<30;i++){
17         for(int j=0;j<i-1;j++){
18             res[i][j]='D';
19         }
20         res[i][i-1]='R';
21         res[i][i]='B';
22         for(int j=i+1;j<30;j++){
23             res[i][j]='D';
24         }
25     }
26     for(int i=0;i<30;i++){
27         if(k&(1<<i))res[i+1][i]='B';
28     }
29     cout<<n<<" "<<m<<"\n";
30     for(int i=0;i<n;i++){
31         for(int j=0;j<m;j++){
32             cout<<res[i][j];
33         }
34         cout<<"\n";
35     }
36     return 0;
37 }

 

Guess you like

Origin www.cnblogs.com/charles1999/p/12288606.html