模拟/usaco 1.2.2 Transformations

题意

  给出一个n*n的原始矩阵图形,一个n*n的变换后矩阵图形,再给出7种变换法则,问是哪种变换

分析

  纯模拟,写的我心烦,其实我就该多锻炼锻炼这种题

  话说翻了一下一年半前刚学编程的程序,当时把这道题看作神题啊,“多麻烦的模拟!”,然后照猫画虎写了个程序,才几十行- -

  现在..呵呵了 比起有算法的东西 真是简单..不过我还磨叽了二十分钟写了不到200行还贡献了一次WA

  至于为啥WA?泥煤又是没看清题..注意要输出最小的变换

Accepted Code

无视乱七八糟的输出吧

  1 {
  2 ID: jessiel2
  3 PROG: transform
  4 LANG: PASCAL
  5 }
  6 Program transform;
  7 Const
  8   Infile = 'transform.in';
  9   Outfile = 'transform.out';
 10 Type
 11   arr = Array[0..15,0..15]Of Char;
 12 Var
 13   i,j,n:Longint;
 14   a,b,c:Arr;
 15 Function check(b,c:Arr):Boolean;
 16 Var
 17   i,j:Longint;
 18 Begin
 19   For i:=1 To n Do Begin
 20     For j:=1 To n Do
 21       If c[i,j]<>b[i,j] Then Exit(false);
 22   End;
 23   Exit(true);
 24 End;
 25 
 26 Function change1(a,c:Arr):Arr;
 27 Var
 28   i,j:Longint;
 29 Begin
 30   For i:=1 To n Do Begin
 31     For j:=1 To n Do c[j,n-i+1]:=a[i,j];
 32   End;
 33   Exit(c);
 34 End;
 35 Function change2(a,c:Arr):Arr;
 36 Var
 37   c1:Arr;
 38 Begin
 39   c:=change1(a,c);
 40   c1:=c;
 41   c1:=change1(c,c1);
 42   c:=c1;
 43   Exit(c);
 44 End;
 45 Function change3(a,c:Arr):Arr;
 46 Var
 47   c1:Arr;
 48 Begin
 49   c1:=change2(a,c1);
 50   c:=change1(c1,c);
 51   Exit(c);
 52 End;
 53 
 54 Function change4(a,c:Arr):Arr;
 55 Var
 56   i,j:Longint;
 57 Begin
 58   For i:=1 To n Do Begin
 59     For j:=1 To n Do c[i,j]:=a[i,n-j+1];
 60   End;
 61   Exit(c);
 62 End;
 63 Function change51(a,c:Arr):Arr;
 64 Var
 65   c1:Arr;
 66 Begin
 67   c1:=change4(a,c1);
 68   c:=change1(c1,c);
 69   Exit(c);
 70 End;
 71 Function change52(a,c:Arr):Arr;
 72 Var
 73   c1:Arr;
 74 Begin
 75   c1:=change4(a,c1);
 76   c:=change2(c1,c);
 77   Exit(c);
 78 End;
 79 Function change53(a,c:Arr):Arr;
 80 Var
 81   c1:Arr;
 82 Begin
 83   c1:=change4(a,c1);
 84   c:=change3(c1,c);
 85   Exit(c);
 86 End;
 87 Procedure print(c:Arr);
 88 Var
 89   i,j:Longint;
 90 Begin
 91   For i:=1 To n Do Begin
 92     For j:=1 To n Do Write(c[i,j]);
 93     WriteLn;
 94   End;
 95   WriteLn;
 96 End;
 97 
 98 Begin
 99   Assign(input,infile);Reset(Input);
100   Assign(output,outfile);Rewrite(output);
101   ReadLn(n);
102   For i:=1 To n Do Begin
103     For j:=1 To n Do Read(a[i,j]);
104     ReadLn;
105   End;
106   For i:=1 To n Do Begin
107     For j:=1 To n Do Read(b[i,j]);
108     ReadLn;
109   End;
110   c:=change1(a,c);
111   //print(c);
112 
113   If check(b,c) Then Begin
114     WriteLn(1);
115     Close(input);Close(output);
116     halt;
117   End;
118 
119   c:=change2(a,c);
120   //print(c);
121 
122   If check(b,c) Then Begin
123     WriteLn(2);
124     Close(input);Close(output);
125     halt;
126   End;
127 
128   c:=change3(a,c);
129   //print(c);
130 
131   If check(b,c) Then Begin
132     WriteLn(3);
133     Close(input);Close(output);
134     halt;
135   End;
136 
137   c:=change4(a,c);
138   //print(c);
139 
140   If check(b,c) Then Begin
141     WriteLn(4);
142     Close(input);Close(output);
143     halt;
144   End;
145 
146   c:=change51(a,c);
147   If check(b,c) Then Begin
148     WriteLn(5);
149     Close(input);Close(output);
150     halt;
151   End;
152   c:=change52(a,c);
153   If check(b,c) Then Begin
154     WriteLn(5);
155     Close(input);Close(output);
156     halt;
157   End;
158   c:=change53(a,c);
159   If check(b,c) Then Begin
160     WriteLn(5);
161     Close(input);Close(output);
162     halt;
163   End;
164   If check(a,b) Then Begin
165     WriteLn(6);
166     Close(input);Close(output);
167     halt;
168   end;
169   WriteLn(7);
170   Close(input);Close(output);
171 End.

 

posted @ 2013-05-06 20:58  Rinyo  阅读(186)  评论(0编辑  收藏  举报