Transformations Block Conversion USACO Analog Array Mathematics Patience

Keywords: PHP

1006: 1.2.2 Transformations Block Conversion

Time limit: 1 Sec Memory limit: 128 MB
Submission: 10. Solution: 7
[Submission] [state] [Discussion Edition ] [Proposer: External Import]

Topic Description

1.2.2 Transformations Block Conversion

(transform.pas/c/cpp)

A black-and-white tile pattern of a square of N x N (1<=N<=10) is converted into a new square pattern. Write a program to find the smallest way to convert the original pattern into a new one according to the following conversion methods:

1: Turn 90 degrees: The pattern turns 90 degrees clockwise.  

2: Turn 180 degrees: The pattern turns 180 degrees clockwise.  

3: Turn 270 degrees: The pattern turns 270 degrees clockwise.  

4: Reflection: The pattern is reversed horizontally (with the central plumb line as the center to form the mirror image of the original pattern).  

5: Combination: The pattern is reversed horizontally and then converted again according to one to three.  

6: No change: the original pattern does not change.  

7: Invalid conversion: No new pattern can be obtained by the above method.  

If there are many conversion methods available, choose the one with the smallest serial number.  

Only one step in 1-7 is used to complete the transformation.  

format

PROGRAM NAME: transform 

INPUT FORMAT: 

file (transform.in) 

Line 1: A single integer N.  

Line 2 to Line N+1: Line N has N characters per line (not "@" or "-"); this is the square before conversion.  

Line N+2 to line 2*N+1: Line N has N characters per line (either "@" or "-"); this is the converted square.  

OUTPUT FORMAT: 

file (transform.out) 

A single line containing a number between 1 and 7 (described above) indicates the need to convert the square before conversion to the square after conversion.  

SAMPLE INPUT

3
@-@
---
@@-
@-@
@--
--@

SAMPLE OUTPUT

1

 

Tips

 

Source/classification

USACO-01 

God, it's a super simulation.

It's just a little difficult when you think about it.

Let's do a conditional analysis.

 

Well, it's still knocked out. It's a test of endurance.

I sympathize with this bunch of functions that return bool values to and fro ~O() Oha~

Let's not talk about sticky code.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char a[15][15],Endmatrix[15][15],b[15][15],bb[15][15];
 4 bool check(int n){
 5     for(int i=1;i<=n;i++)
 6         for(int j=1;j<=n;j++)
 7             if(b[i][j]!=Endmatrix[i][j])
 8                 return false;
 9     return true;
10 }
11 void init(int n){
12     for(int i=1;i<=n;i++) 
13         for(int j=1;j<=n;j++)
14             cin>>a[i][j];
15     for(int i=1;i<=n;i++)
16         for(int j=1;j<=n;j++)
17             cin>>Endmatrix[i][j];
18 }
19 void Type_1(int n){
20     for(int i=1;i<=n;i++) 
21         for(int j=1;j<=n;j++)
22             b[j][n-i+1]=a[i][j];
23 }
24 void Type_2(int n){
25     for(int i=1;i<=n;i++)
26             for(int j=1;j<=n;j++)
27                 b[n-i+1][n-j+1]=a[i][j];
28 }
29 void Type_3(int n){
30     for(int i=1;i<=n;i++)
31         for(int j=1;j<=n;j++)
32             b[n-j+1][i]=a[i][j];
33 }
34 void Type_4(int n){
35     for(int i=1;i<=n;i++)
36         for(int j=1;j<=n;j++)
37             b[i][n-j+1]=a[i][j];
38 }
39 bool Type_5(int n){
40     for(int i=1;i<=n;i++)
41         for(int j=1;j<=n;j++)
42             bb[i][n-j+1]=a[i][j];
43     for(int i=1;i<=n;i++) 
44         for(int j=1;j<=n;j++)
45             b[j][n-i+1]=bb[i][j];
46     if(check(n)) return true;
47     for(int i=1;i<=n;i++)
48         for(int j=1;j<=n;j++)
49             b[n-i+1][n-j+1]=bb[i][j];
50     if(check(n)) return true;
51     for(int i=1;i<=n;i++)
52         for(int j=1;j<=n;j++)
53             b[n-j+1][i]=bb[i][j];
54     return check(n);
55 }
56 bool Control(int Type,int n){
57     if(Type==7) return true;
58     if(Type==1) {Type_1(n);return check(n);}
59     if(Type==2) {Type_2(n);return check(n);}
60     if(Type==3) {Type_3(n);return check(n);}
61     if(Type==4) {Type_4(n);return check(n);}
62     if(Type==5) return Type_5(n);
63     if(Type==6) return check(n);
64 }
65 int main(){
66     int n; scanf("%d",&n);
67     init(n);
68     for(int i=1;i<=7;i++)
69         if(Control(i,n)){
70             printf("%d",i);
71             break;
72         }
73     return 0;
74 }

Come on.~

Posted by rajb on Sat, 03 Aug 2019 00:57:54 -0700