출처: https://train.usaco.org/usacogate


문제 설명

A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations:

#1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
#2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
#3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
#4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
#5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
#6: No Change: The original pattern was not changed.
#7: Invalid Transformation: The new pattern was not obtained by any of the above methods.
In the case that more than one transform could have been used, choose the one with the minimum number above.

입력 

Line 1: A single integer, N
Line 2..N+1: N lines of N characters (each either `@' or `-'); this is the square before transformation
Line N+2..2*N+1: N lines of N characters (each either `@' or `-'); this is the square after transformation

출력

A single line containing the number from 1 through 7 (described above) that categorizes the transformation required to change from the `before' representation to the `after' representation.

입력 예

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

출력 예

1


문제 풀이 내용

N x N 보드를 구성하고, 그 보드를 회전시키는 문제이다. 보드를 돌렸을때 셀이 움직이는 구조를 규칙으로 만들어서, 변화된 보드와 비교해서 해당하는 변화를 찾아내서 출력한다.

프로그램 내용

더보기
bool rotate90(int org[MAX_TILE][MAX_TILE], int chg[MAX_TILE][MAX_TILE], int t_size)
 
bool rotate180(int org[MAX_TILE][MAX_TILE], int chg[MAX_TILE][MAX_TILE], int t_size)

bool rotate270(int org[MAX_TILE][MAX_TILE], int chg[MAX_TILE][MAX_TILE], int t_size)

bool reflected(int org[MAX_TILE][MAX_TILE], int chg[MAX_TILE][MAX_TILE], int t_size)

bool boardsAreEqual(int org[MAX_TILE][MAX_TILE], int chg[MAX_TILE][MAX_TILE], int t_size)

    int org[MAX_TILE][MAX_TILE];
    int refl[MAX_TILE][MAX_TILE];
    int chg[MAX_TILE][MAX_TILE];

    // reading original tiles
    for(int i = 0; i < tile_Size; ++i)
    {
	...
    }

    // reading target tiles
    for(int i = 0; i < tile_Size; ++i)
    {
	...
	}

    // reflected tiles
    for(int i = 0; i < tile_Size; ++i)
    {
	...
	}

/*
#1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
#2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
#3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
#4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
#5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
#6: No Change: The original pattern was not changed.
#7: Invalid Transformation: The new pattern was not obtained by any of the above methods.
*/
    int result = 0;
    if(rotate90(org, chg, tile_Size)) result = 1;
    else if(rotate180(org, chg, tile_Size)) result = 2;
    else if(rotate270(org, chg, tile_Size)) result = 3;
    else if(reflected(org, chg, tile_Size)) result = 4;
    else if(rotate90(refl, chg, tile_Size) || rotate180(refl, chg, tile_Size) || rotate270(refl, chg, tile_Size)) result = 5;
    else if(boardsAreEqual(org, chg, tile_Size)) result = 6;
    else result = 7;
    fout << result << "\n";

 

Chapter 1. Getting started

'USACO Training' 카테고리의 다른 글

Problem 1.3.5 Palindromic Squares  (0) 2019.09.08
Problem 1.3.4 Name That Numbers  (0) 2019.09.07
Problem 1.3.2 Milking Cow  (0) 2019.09.07
Problem 1.2.7 Broken Necklace  (0) 2019.09.07
Problem 1.2.6 Friday the Thirteenth  (0) 2019.09.07

+ Recent posts