[Usaco1.2 _ 2]★Transformations block Conversion

Source: Internet
Author: User

The black-and-white tile pattern of an n x n (1 <= n <= 10) Square is converted into a new square pattern. Write a program to find the minimum way to convert the original pattern into a new pattern using the following column conversion method:

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

2: turn 180 degrees: The pattern turns clockwise to 180 degrees.

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

4: Reflection: The image is flipped horizontally (the image with the central vertical line as the heart to form the original pattern ).

5: combination: The pattern is flipped horizontally, and then converted again according to one to three.

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

7: Invalid conversion: the new pattern cannot be obtained using the above method.

If you have multiple available conversion methods, select the one with the smallest serial number.

Only one step from 1 to 7 is used to complete the conversion.

[Edit] format

Program name: Transform

Input Format:

(File transform. In)

The first line is a separate integer n.

Line 2 to line n + 1: line N contains n characters (either "@" or "-"); this is the square before conversion.

Line n + 2 to line 2nd * n + 1: line N contains n characters ("@" or "-"). This is the converted square.

Output Format:

(File transform. out)

A separate row contains a number ranging from 1 to 7 (as described above), indicating that the square before conversion needs to be converted into the transformation method of the square after conversion.

[Edit] sample input
3@[email protected]---@@-@[email protected]@--[email protected]
[Edit] sample output
1


/* ID: zwcwu52prog: transformlang: C ++ */# include <iostream> # include <fstream> # include <string> using namespace STD; char blksrc [10] [10], blkdst [10] [10]; // source array, target matrix int main () {ofstream fout ("transform. out "); ifstream fin (" transform. in "); unsigned N; // order unsigned num = 7; // solution number fin> N; // read the source array for (unsigned I = 0; I <n; I ++) {for (unsigned J = 0; j <n; j ++) {fin> blksrc [I] [J];} // read the target phalanx for (unsigned I = 0; I <n; I ++) {for (unsigned J = 0; j <n; j ++) {fin> blkdst [I] [J];} do {bool B = true; // check whether the do {bool B = true; // check by solution 1 for (unsigned I = 0; I <n; I ++) {for (unsigned J = 0; j <n; j ++) {If (blksrc [I] [J]! = Blkdst [J] [n-I-1]) {B = false; break ;}}if (true = B) {num = 1; break ;} // detect B = true by solution 2; for (unsigned I = 0; I <n; I ++) {for (unsigned J = 0; j <N; j ++) {If (blksrc [I] [J]! = Blkdst [n-I-1] [n-J-1]) {B = false; break ;}} if (true = B) {num = 2; break;} // detect B = true by solution 3; for (unsigned I = 0; I <n; I ++) {for (unsigned J = 0; j <N; j ++) {If (blksrc [I] [J]! = Blkdst [n-J-1] [I]) {B = false; break ;}}if (true = B) {num = 3; break ;} // check according to solution 4 B = true; For (unsigned I = 0; I <n; I ++) {for (unsigned J = 0; j <N; j ++) {If (blksrc [I] [J]! = Blkdst [I] [n-J-1]) {B = false; break ;}}if (true = B) {num = 4; break ;} // check according to solution 5 B = true; For (unsigned I = 0; I <n; I ++) {for (unsigned J = 0; j <N; j ++) {If (blksrc [I] [J]! = Blkdst [n-J-1] [n-I-1]) {B = false; break ;}} if (true = B) {num = 5; break;} // according to solution 5 detection B = true; For (unsigned I = 0; I <n; I ++) {for (unsigned J = 0; j <N; j ++) {If (blksrc [I] [J]! = Blkdst [n-I-1] [J]) {B = false; break ;}}if (true = B) {num = 5; break ;} // check according to solution 5 B = true; For (unsigned I = 0; I <n; I ++) {for (unsigned J = 0; j <N; j ++) {If (blksrc [I] [J]! = Blkdst [J] [I]) {B = false; break ;}}if (true = B) {num = 5; break ;} // check B = true according to solution 6; For (unsigned I = 0; I <n; I ++) {for (unsigned J = 0; j <N; j ++) {If (blksrc [I] [J]! = Blkdst [I] [J]) {B = false; break ;}}if (true = B) {num = 6; break ;}} while (0 ); fout <num <Endl; return 0 ;}


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.