G title card guide


I played the G question of the Sengang Cup for more than an hour, and finally ac; I
vomited. There is a card on the table of the
question description
. The card is an N * N grid. Each grid contains an integer on both sides. . At the beginning, the card is placed face up on the table. Please judge
the number distribution of the grid in the card after performing the following operations:
Operation 1: 1 xy val means to modify the number in row x and column y to val. Modify the current face up element. (1 <= x, y <= n)
Operation 2: 2 xy Exchange the x-th row and the y-th row of the card. (x, i) <–> (y, i) where (1 <= i <= n). (1 <= x, y <= n)
Operation 3: 3 xy Exchange the xth column and the xth column of the card. (i, x) <–> (i, y) where (1 <= i <= n). (1 <= x, y <= n)
Operation 4:4 Turn the card over, the front side becomes the back side, and the back side becomes the front side.
Operation 5: 5 Rotate the card 90 degrees clockwise.
Operation 6: 6 Rotate the card 180 degrees clockwise.
Operation 7: 7 Rotate the card clockwise by 270 degrees.
Note: The front and back sides of each grid are a whole, and the back elements change their positions along with the front elements during the exchange and rotation.
Input description: The
first line of input contains two integers n, m. Indicates the size of the card grid and the number of operations.
Then follow n rows with n integers in each row, representing the n * n grid on the front of the card,
and then follow n rows with n integers in each row, representing the n * n grid on the back of the card.
Then follow m lines, one operation instruction per line.
Output description:
After the m operation instructions are executed, the answer is output.
Output the first n lines, each line of n integers, representing the front of the card.
Then output n rows with n integers in each row, representing the reverse side of the card.
Example 1
Input
Copy
3 7
1 2 3
4 5 6
7 8 9
7 8 9
4 5 6
1 2 3
1 1 3 0
2 1 3
3 2 3
4
5
6
7
Output
Copy
8 9 7
5 6 4
2 3 1
2 0 1
5 6 4
8 9 7
Description
Front and back
1 2 3 7 8 9
4 5 6 4 5 6
7 8 9 1 2 3
After performing 1 1 3 0:
Front and back
1 2 0 7 8 9
4 5 6 4 5 6
7 8 9 1 2 3
After performing 2 1 3:
7 8 9 1 2 3
4 5 6 4 5 6
1 2 0 7 8 9
After performing 3 2 3:
7 9 8 1 3 2
4 6 5 4 6 5
1 0 2 7 9 8
After performing 4:
1 3 2 7 9 8
4 6 5 4 6 5
7 9 8 1 0 2
After executing 5:
7 4 1 1 4 7
9 6 3 0 6 9
8 5 2 2 5 8
After executing 6:
2 5 8 8 5 2
3 6 9 9 6 0
1 4 7 7 4 1
After executing 7:
8 9 7 2 0 1
5 6 4 5 6 4
2 3 1 8 9 7
Remarks:
1 <= n, m, val <= 100 The
code is as follows

#include<iostream>
#include<algorithm>
using namespace std;
const int N=105;
int n,m;
int a[N][N];//正面
int b[N][N];//反面
//方案一
void fan_1(int x,int y,int val){
    
    
    a[x][y]=val;
}
//方案二
void fan_2(int x,int y){
    
    
    int c[N];int d[N];
    for(int i=0;i<n;i++) c[i]=a[x][i],d[i]=b[x][i];
    for(int i=0;i<n;i++) a[x][i]=a[y][i],b[x][i]=b[y][i];
    for(int i=0;i<n;i++) a[y][i]=c[i],b[y][i]=d[i];
}
//方案三
void fan_3(int x,int y){
    
    
    int c[N];int d[N];
    for(int i=0;i<n;i++) c[i]=a[i][x],d[i]=b[i][x];
    for(int i=0;i<n;i++) a[i][x]=a[i][y],b[i][x]=b[i][y];
    for(int i=0;i<n;i++) a[i][y]=c[i],b[i][y]=d[i];
}
void fan_4(){
    
    
    int c[N][N];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            c[i][j]=a[i][j];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            a[i][j]=b[i][j];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            b[i][j]=c[i][j];
}
//方案五
void fan_5(){
    
    
    int c[N][N];int d[N][N];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
    
    
            c[i][j]=a[n-j-1][i];
            d[i][j]=b[n-j-1][i];
        }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
    
    
            a[i][j]=c[i][j];
            b[i][j]=d[i][j];
        }
}
//方案六
void fan_6(){
    
    
    int c[N][N];int d[N][N];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
    
    
            c[i][j]=a[n-i-1][n-j-1];
            d[i][j]=b[n-i-1][n-j-1];
        }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
    
    
            a[i][j]=c[i][j];
            b[i][j]=d[i][j];
        }
}
//方案七
void fan_7(){
    
    
    int c[N][N];int d[N][N];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
    
    
            c[i][j]=a[j][n-i-1];
            d[i][j]=b[j][n-i-1];
        }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
    
    
            a[i][j]=c[i][j];
            b[i][j]=d[i][j];
        }
}
int main(){
    
    
    cin>>n>>m;
    //输入正反数
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>b[i][j];
    //执行操作
    for(int i=0;i<m;i++){
    
    
        int f_a;
        cin>>f_a;//执行方案输入
        //到底是用swith还是级联,我选择swith;
        int x,y,val;
        switch(f_a){
    
    
        case 1:
            cin>>x>>y>>val;fan_1(x-1,y-1,val);break;
        case 2:
            cin>>x>>y;fan_2(x-1,y-1);break;
        case 3:
            cin>>x>>y;fan_3(x-1,y-1);break;
        case 4:
            fan_4();break;
        case 5:
            fan_5();break;
        case 6:
            fan_6();break;
        case 7:
            fan_7();break;
        }
    }
    //输出正面
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cout<<a[i][j]<<(j!=n-1?" ":"\n");
    //输出反面
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cout<<b[i][j]<<(j!=n-1?" ":"\n");
    return 0;
}

A cute new helpless, only use this stupid way 0.0 is
not the president and has to ask me to fight,
I’m too lazy to fight

Guess you like

Origin blog.csdn.net/m0_52361859/article/details/111850089