2023小云雀杯比赛回顾-#旋旋旋旋旋旋旋

ALL_OF_US

2023-05-03 11:25:33

Solution

暴力/队列

思路讲解:

1. 暴力方法

第一种:循环访问并向前移

forin a[n+1][i]=a[1][i];
forin forjn a[i][j]=a[i+1][j];

第二种:直接\text{swap}

for(int i=1;i<n;i++) swap(a[i],a[i+1]);

第一种:循环访问并向后移

forin a[0][i]=a[n][i];
    for(int i=n;i>=1;i--)forjn a[i][j]=a[i-1][j];

第二种:直接\text{swap}

for(int i=n;i>1;i--)
    swap(a[i],a[i-1]);

变成:

int t[N][N];
    forin forjn t[j][n-i+1]=a[i][j];
    forin forjn a[i][j]=t[i][j];

暴力方法不给出代码 要代码的看这里

2. deque

定义双端队列a和b,表示行的位置关系与列的位置关系

定义bool g为记录图表方向

输入初始位置关系:

forin a.push_back(i),b.push_back(i);

a.\text{front()}移动到a.\text{back()}

a.push_back(a.front());
a.pop_front();

a.\text{back()}移动到a.\text{front()}

a.push_front(a.back());
a.pop_back();

定义函数f为反转队列函数:

deque<int> f(deque<int> x){
    deque<int> t;
    while(!x.empty()){
        t.push_front(x.front());
        x.pop_front();
    }
    return t;
}

则f5为:

void f5(){
    swap(a,b);
    b=f(b);
}

记得输出

暴力输出:

forin{
    forjn cout<<a[i][j]<<" ";
        cout<<"\n";
    }
    cout<<"\n";

deque输出:

if(!g) for(int j=1;j<=a.size();j++){
    for(int k=1;k<=b.size();k++){
        cout<<q[a.front()][b.front()]<<" ";
        b.push_back(b.front()); b.pop_front();
    } 
    a.push_back(a.front()); a.pop_front();
    cout<<endl;
}else for(int j=1;j<=a.size();j++){
    for(int k=1;k<=b.size();k++){
        cout<<q[b.front()][a.front()]<<" ";
        b.push_back(b.front()); b.pop_front();
    } 
    a.push_back(a.front()); a.pop_front();
    cout<<endl;
}
cout<<endl;

代码如下:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define mem memset
#define pin(c) scanf("%lld",&(c))
#define forin for(int i=1;i<=n;i++)
#define forim for(int i=1;i<=m;i++)
#define forjn for(int j=1;j<=n;j++)
#define forjm for(int j=1;j<=m;j++)
#define forkn for(int k=1;k<=n;k++)
#define forkm for(int k=1;k<=m;k++)
#define Forx(c,l,r,p) for(int (c)=(l);(c)<=(r);(c)+=(p))
#define Fory(c,l,r,p) for(int (c)=(l);(c)>=(r);(c)-=(p))
const int N=1e2+10;
const int INF=0x3f3f3f3f;
deque<int> a,b;
int n,q[N][N];
deque<int> f(deque<int> x){
    deque<int> t;
    while(!x.empty()){
        t.push_front(x.front());
        x.pop_front();
    }
    return t;
}
void f5(){
    swap(a,b);
    b=f(b);
}
signed main(){
    int t,c;
    bool g=0;
    pin(n),pin(t);
    forin forjn pin(q[i][j]);
    forin a.push_back(i),b.push_back(i);
    for(int i=1;i<=t;i++){
        pin(c);
        if(c==1){
            a.push_back(a.front());
            a.pop_front();
        }else if(c==2){
            a.push_front(a.back());
            a.pop_back();
        }else if(c==3){
            b.push_back(b.front());
            b.pop_front();
        }else if(c==4){
            b.push_front(b.back());
            b.pop_back();
        }else if(c==5){
            f5(); g=!g;
        }else if(c==6){
            f5(),f5();
        }else if(c==7){
            f5(),f5(),f5(); g=!g;
        }
        if(!g) for(int j=1;j<=a.size();j++){
            for(int k=1;k<=b.size();k++){
                cout<<q[a.front()][b.front()]<<" ";
                b.push_back(b.front()); b.pop_front();
            } 
            a.push_back(a.front()); a.pop_front();
            cout<<endl;
        }else for(int j=1;j<=a.size();j++){
            for(int k=1;k<=b.size();k++){
                cout<<q[b.front()][a.front()]<<" ";
                b.push_back(b.front()); b.pop_front();
            } 
            a.push_back(a.front()); a.pop_front();
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}