跳至正文

USACO 1.2.2 Transformations

  • OI路程

  这题没什么别的巧,就是硬搜,我犯的唯一一个错误就是使用了strcmp来进行判断,但是又没有给字符串设置结尾标识’\0’,幸运的是我在提交前查出来了,所以还是一次性提交成功,哈哈 !代码如下:

/
LANG:
C

ID: logoo2
PROG:
transform

/
#include <stdio.h>
#include
<string.h>
typedef struct{
        char map[10][11];
}pic;
int n;
pic map, end;

pic change1(pic
box)
{
        int i, j;
        pic
tmp;
        for(i = 0; i < n; i++){
                for(j = 0; j < n;
j++){
                        tmp.map[j][n – 1 –
i] = box.map[i][j];
                }
                /
                mistack
1:

                  忘记增加结束标识
                
/
                tmp.map[i][n] = ‘\0’;
        }
        return tmp;
}

int com(pic a, pic b)
{
        int i;
        for(i = 0; i < n;
i++){
                if(strcmp(a.map[i],
b.map[i]) != 0){
                        return 1;
                }
        }
        return 0;
}

pic
change2(pic box)
{
        int i,
j;
        pic tmp;
        for(i =
0; i < n; i++){
                for(j = 0; j < n;
j++){
                        tmp.map[i][n – 1 –
j] = box.map[i][j];
                }
                tmp.map[i][n] =
‘\0’;
        }
        return tmp;
}

int main(void)
{
        int i;
        freopen("transform.in", "r", stdin);
        freopen("transform.out", "w", stdout);
        scanf("%d", &n);
        for(i = 0; i < n;
i++){
                scanf("%s\n", map.map[i]);
        }
        for(i = 0; i < n;
i++){
                scanf("%s\n", end.map[i]);
        }
        if(com(change1(map), end) == 0){
                printf("1\n");
        }else if(com(change1(change1(map)), end) == 0){
                printf("2\n");
        }else if(com(change1(change1(change1(map))), end) == 0){
                printf("3\n");
        }else if(com(change2(map), end) == 0){
                printf("4\n");
        }else if((com(change1(change2(map)), end) == 0)
||
                (com(change1(change1(change2(map))), end) == 0)
||
                (com(change1(change1(change1(change2(map)))), end) ==
0)){
                printf("5\n");
        }else if(com(map,
end) == 0){
                printf("6\n");
        }else{
                printf("7\n");
        }
        return 0;
}

发表回复

您的电子邮箱地址不会被公开。