【USACO题库】1.2.2 Transformations方块转换

来源:互联网 发布:湖南卫视知乎 编辑:程序博客网 时间:2024/04/28 15:06

题目描述:

一块N x N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案。写一个程序来找出将原始图案按照以下列转换方法转换成新图案的最小方式:

#1:转90度:图案按顺时针转90度。
#2:转180度:图案按顺时针转180度。
#3:转270度:图案按顺时针转270度。
#4:反射:图案在水平方向翻转(形成原图案的镜像)。
#5:组合:图案在水平方向翻转,然后按照#1-#3之一转换。
#6:不改变:原图案不改变。
#7:无效转换:无法用以上方法得到新图案。

如果有多种可用的转换方法,请选择序号最小的那个。

输入
第一行: 单独的一个整数N。
第二行到第N+1行: N行每行N个字符(不是“@”就是“-”);这是转换前的正方形。
第N+2行到第2*N+1行: N行每行N个字符(不是“@”就是“-”);这是转换后的正方形。

输出
单独的一行包括1到7之间的一个数字(在上文已描述)表明需要将转换前的正方形变为转换后的正方形的转换方法。


样例输入
3
@-@
---
@@-
@-@
@--
--@

样例输出
1


这道题目其实比较简单,只是对应的7种转换方法用7种不同的公式而已,公式很容易找到,所以直接贴代码:
type        arr=array[1..20,1..20] of char;var        a,b,x:arr;        n,i,j:longint;function tx1(a,b:arr):boolean;var        i,j:longint;begin        for i:=1 to n do                for j:=1 to n do                        if a[i,j]<>b[n-j+1,i] then exit(false);        exit(true);end;function tx2(a,b:arr):boolean;var        i,j:longint;begin        for i:=1 to n do                for j:=1 to n do                        if a[i,j]<>b[n-i+1,n-j+1] then exit(false);        exit(true);end;function tx3(a,b:arr):boolean;var        i,j:longint;begin        for i:=1 to n do                for j:=1 to n do                        if a[i,j]<>b[j,n-i+1] then exit(false);        exit(true);end;function tx4(a,b:Arr):boolean;var        i,j:longint;begin        for i:=1 to n do                for j:=1 to n do                        if a[i,j]<>b[i,n-j+1] then exit(false);        exit(true);end;function tx5(a,b:arr):boolean;var        i,j:longint;begin        for i:=1 to n do                for j:=1 to n do                        x[i,j]:=b[i,n-j+1];        if tx1(a,x) then exit(true);        if tx2(a,x) then exit(true);        if tx3(a,x) then exit(true);end;function tx6(a,b:arr):boolean;var        i,j:longint;begin        for i:=1 to n do                for j:=1 to n do                        if a[i,j]<>b[i,j] then exit(false);        exit(true);end;begin        readln(n);        for i:=1 to n do        begin                for j:=1 to n do                        read(b[i,j]);                readln;        end;        for i:=1 to n do        begin                for j:=1 to n do                        read(a[i,j]);                readln;        end;        if tx1(a,b) then writeln(1) else        if tx2(a,b) then writeln(2) else        if tx3(a,b) then writeln(3) else        if tx4(a,b) then writeln(4) else        if tx5(a,b) then writeln(5) else        if tx6(a,b) then writeln(6) else        writeln(7);end.

0 0