USACO transform

  直接暴力模拟即可:

  

/*
    ID: m1500293
    LANG: C++
    PROG: transform
*/
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int n;
char tps[15][15];
char s[15][15];
char e[15][15];

bool IsSame(char a[][15], char b[][15])
{
    bool flog = true;
    for(int i=0; i<n&&flog; i++)
        for(int j=0; j<n&&flog; j++)
            if(a[i][j] != b[i][j]) flog = false;
    return flog;
}

void debug(char a[][15])
{
    printf("debug========================\n");
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            printf("%c", a[i][j]);
        printf("\n");
    }
}

void rotate_90(char a[][15])
{
    //debug(a);
    char b[15][15];
    int ii=0, jj=0;
    for(int j=0; j<n; j++)
        for(int i=n-1; i>=0; i--)
        {
            b[ii][jj++] = a[i][j];
            if(jj == n) ii++, jj=0;
        }
    memcpy(a, b, sizeof(b));
    //debug(a);
}

void reflection(char a[][15])
{
    //debug(a);
    for(int i=0; i<n; i++)
        for(int j=0; j<n/2; j++)
        {
            swap(a[i][j], a[i][n-1-j]);
        }
    //debug(a);
}

int main()
{
    freopen("transform.in", "r", stdin);
    freopen("transform.out", "w", stdout);
    while(scanf("%d", &n) == 1)
    {
        for(int i=0; i<n; i++)    scanf("%s", s[i]);
        for(int i=0; i<n; i++)  scanf("%s", e[i]);
        memcpy(tps, s, sizeof(s));
        //rotate_90(tps);
        //reflection(tps);
        int res = 0x3f3f3f3f;
        if(IsSame(tps, e))
            res = min(res, 6);
        if(rotate_90(tps), IsSame(tps, e))
            res = min(res, 1);
        if(rotate_90(tps), IsSame(tps, e))
            res = min(res, 2);
        if(rotate_90(tps), IsSame(tps, e))
            res = min(res, 3);
        rotate_90(tps);
        reflection(tps);
        if(IsSame(tps, e))
            res = min(res, 4);
        for(int i=0; i<3; i++)
        {
            rotate_90(tps);
            if(IsSame(tps, e)) res = min(res, 5);
        }
        if(res != 0x3f3f3f3f)
            printf("%d\n", res);
        else
            printf("7\n");
    }
    return 0;
}
时间: 2024-07-28 15:03:07

USACO transform的相关文章

【USACO】Transformations(模拟)

Transformations 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

【USACO】Transformations

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 l

COGS 696. [IOI1996][USACO 2.3] 最长前缀

★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当于 Pascal 中的 “+” 运算符)组成一个序列 S ,那么我们认为序列 S 可以分解为 P 中的元素.元素不一定要全部出现(如下例中B

stl中的transform()注意其与for_each的不同点(有无返回值)

#include<iostream> using namespace std; #include"vector" #include"algorithm" #include"list" #include"functional" // void PrintV(vector <int > &temp) { for (vector<int>::iterator it = temp.begin

trasition,transform,旋转

<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> body{ margin: 100px; } .div1{ width: 200px; height: 150px; transform: rotate(30deg); background-color: ant

CSS3 transform 属性详解(skew, rotate, translate, scale)

写这篇文章是因为在一个前端QQ群里,网友 "小豆豆" (应他要求要出现他的网名......) ,问skew的角度怎么算,因为他看了很多文章还是不能理解skew的原理.于是,我觉得有必要写个博文,帮助那些不懂的人,让他们看了此文就懂. 进入正题: 先说明下,电脑屏幕的XY轴跟我们平时所说的直角坐标系是不一样的.如下图: 图上的盒子就是代表我们的电脑屏幕,原点就是屏幕的左上角,竖直向下为X轴正方向,水平向右为Y轴正方向. 1.倾斜skew 先看图 每个图下方都有skew的参数.粗的红色的线

css3中的变形(transform)、过渡(transtion)、动画(animation)

Transform字面上就是变形,改变的意思.在CSS3中transform主要包括以下几种:旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix.下面我们一起来看看CSS3中transform的旋转rotate.扭曲skew.缩放scale和移动translate具体如何实现,老样子,我们就从transform的语法开始吧.是构成transtion和animation的基础. 语法: transform : none | <transform-func

css3 2D转换(2D Transform) 动画(Animation)

transform 版本:CSS3 内核类型 写法 Webkit(Chrome/Safari) -webkit-transform Gecko(Firefox) -moz-transform Presto(Opera) -o-transform Trident(IE) -ms-transform W3C transform none:无转换 matrix(<number>,<number>,<number>,<number>,<number>,&

OpenCV Tutorials &mdash;&mdash; Hough Line Transform

霍夫直线变换 -- 用于检测图像中的直线 利用图像空间和Hough参数空间的点--直线对偶性,把图像空间中的检测问题转换到参数空间,通过在参数空间进行简单的累加统计,然后在Hough参数空间中寻找累加器峰值的方法检测直线 Standard and Probabilistic Hough Line Transform OpenCV implements two kind of Hough Line Transforms: The Standard Hough Transform It consis