求hack
查看原帖
求hack
673294
zyxawa楼主2022/11/27 14:34
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int t,n,m,k,tot,pos,s1[302],s2[302],val[602],col[2000002],a1[4000002],a2[4000002],a3[4000002];
int main(){
    t=read();
    while(t--){
        n=read(),m=read(),k=read();
        memset(s1,0,sizeof(s1));
        memset(s2,0,sizeof(s2));
        tot=0;
        for(int i=1;i<=m;i++) col[i]=read();
        for(int i=1;i<=m;i++){
            if(i%k==1){
                memset(val,0,sizeof(val));
                for(int j=i+k;j<=m&&j<=i+k+k/2-1;j++) val[col[j]]=j-i-k+1;
            }
            for(int j=1;j<n;j++){
                if((s2[j]==0&&s1[j]==col[i])||(s2[j]==col[i])){
                    a1[++tot]=1,a2[tot]=j;
                    if(s2[j]==col[i]) s2[j]=0;
                    else s1[j]=0;
                    goto again;
                }
            }
            for(int j=1;j<n;j++){
                if(s1[j]==col[i]){
                    a1[++tot]=1,a2[tot]=n;
                    a1[++tot]=2,a2[tot]=j,a3[tot]=n;
                    s1[j]=0;
                    swap(s1[j],s2[j]);
                    goto again;
                }
            }
            pos=0;
            for(int j=1;j<n;j++) pos+=(s1[j]==0);
            if(val[col[i]]&&val[col[i]]<=pos){
                for(int j=1;j<n;j++){
                    if(s1[j]==0){
                        a1[++tot]=1,a2[tot]=j;
                        s1[j]=col[i];
                        goto again;
                    }
                }
                for(int j=1;j<n;j++){
                    if(s1[j]&&s2[j]==0){
                        a1[++tot]=1,a2[tot]=j;
                        s2[j]=col[i];
                        goto again;
                    }
                }
            }
            else{
                for(int j=1;j<n;j++){
                    if(s1[j]&&s2[j]==0){
                        a1[++tot]=1,a2[tot]=j;
                        s2[j]=col[i];
                        goto again;
                    }
                }
                for(int j=1;j<n;j++){
                    if(s1[j]==0){
                        a1[++tot]=1,a2[tot]=j;
                        s1[j]=col[i];
                        goto again;
                    }
                }
            }
            if(col[i]==col[i+1]){
                a1[++tot]=1,a2[tot]=n;
                a1[++tot]=1,a2[tot]=n;
                i++;
                goto again;
            }
            for(int j=1;j<n;j++){
                if(s1[j]==col[i+1]){
                    a1[++tot]=1,a2[tot]=j;
                    a1[++tot]=1,a2[tot]=n;
                    a1[++tot]=2,a2[tot]=j,a3[tot]=n;
                    s1[j]=s2[j];
                    s2[j]=col[i];
                    i++;
                    goto again;
                }
            }
            again:;
        }
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(s1[i]==s1[j]&&s1[i]&&s1[j]){
                    a1[++tot]=2,a2[tot]=i,a3[tot]=j;
                    s1[i]=0;
                    s1[j]=0;
                    swap(s1[i],s2[i]);
                    swap(s1[j],s2[j]);
                }
            }
        }
        printf("%d\n",tot);
        for(int i=1;i<=tot;i++){
            printf("%d %d",a1[i],a2[i]);
            if(a1[i]==2) printf(" %d",a3[i]);
            putchar('\n');
        }
    }
    return 0;
}
2022/11/27 14:34
加载中...