P1205 [USACO1.2] 方块转换 Transformations

题目描述

一块 n×n 正方形的黑白瓦片的图案要被转换成新的正方形图案。写一个程序来找出将原始图案按照以下列转换方法转换成新图案的最小方式:

  • 转 90°:图案按顺时针转 90°。
  • 转 180°:图案按顺时针转 180°。
  • 转 270°:图案按顺时针转 270°。
  • 反射:图案在水平方向翻转(以中央铅垂线为中心形成原图案的镜像)。
  • 组合:图案在水平方向翻转,然后再按照 1∼3 之间的一种再次转换。
  • 不改变:原图案不改变。
  • 无效转换:无法用以上方法得到新图案。

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

只使用上述 7 个中的一个步骤来完成这次转换。

输入格式

第一行一个正整数 n

然后 n 行,每行 n 个字符,全部为 @ 或 -,表示初始的正方形。

接下来 n 行,每行 n 个字符,全部为 @ 或 -,表示最终的正方形。

输出格式

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

#include <iostream>
#include <vector>
using namespace std;
void rotate_90(vector<vector<char>> &a){
    int n = a.size();
    vector<vector<char>> res(n, vector<char>(n));
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            res[i][j]=a[n-1-j][i];
        }
    }
     a=res;
}
void rotate_180(vector<vector<char>> &a){
    int n = a.size();
    vector<vector<char>> res(n, vector<char>(n));
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            res[i][j]=a[n-1-i][n-1-i];
        }
    }
     a=res;
}
void rotate_270(vector<vector<char>>&a){
    int n = a.size();
    vector<vector<char>> res(n, vector<char>(n));
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            res[i][j]=a[j][n-1-i];
        }
    }
     a=res;
}
void reflect(vector<vector<char>>&a){
    int n = a.size();
    vector<vector<char>> res(n, vector<char>(n));
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            res[i][j]=a[i][n-1-j];
        }
    }
     a=res;
}
int main(){
    int n;
    cin>>n;
    vector<vector<char>> square_before(n, vector<char>(n));
    vector<vector<char>> square_after(n, vector<char>(n));
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            cin>>square_before[i][j];
        }
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            cin>>square_after[i][j];
        }
    }
    if(square_after==square_before){
        cout<<6;
        return 0;
    }
    rotate_90(square_before);
    if(square_after==square_before){
        cout<<1;
        return 0;
    }
    rotate_90(square_before);
    if(square_after==square_before){
        cout<<2;
        return 0;
    }
    rotate_90(square_before);
    if(square_after==square_before){
        cout<<3;
        return 0;
    }
    rotate_90(square_before);
    reflect(square_before);
    if(square_after==square_before){
        cout<<4;
        return 0;
    }
    rotate_90(square_before);
    if(square_after==square_before){
        cout<<5;
        return 0;
    }
    rotate_90(square_before);
    if(square_after==square_before){
        cout<<5;
        return 0;
    }
    rotate_90(square_before);
    if(square_after==square_before){
        cout<<5;
        return 0;
    }
    cout<<7;
    return 0;
    
    
}

好像有点问题,尽力了,今天先这样吧

评论

  1. 91cyl
    13 小时前
    2026-1-13 23:27:40

    加油牢癫公

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇