SSL JudgeOnline 1089——USACO 1.2 方块转换

34 篇文章 0 订阅
8 篇文章 0 订阅

USACO 1.2 方块转换 (枚举)

Time Limit:10000MS Memory Limit:65536K
Total Submit:37 Accepted:32
Case Time Limit:1000MS

Description

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

1:转90度:图案按顺时针转90度。

2:转180度:图案按顺时针转180度。

3:转270度:图案按顺时针转270度。

4:反射:图案在水平方向翻转(形成原图案的镜像)。

5:组合:图案在水平方向翻转,然后按照#1-#3之一转换。

6:不改变:原图案不改变。

7:无效转换:无法用以上方法得到新图案。

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

Input

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

Output

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

Sample Input

3

@-@

@@-
@-@
@–
–@
Sample Output

1


这题我们枚举每一种情况,如果等于所要转化图案,就输出。没有则输出 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.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值