zoukankan      html  css  js  c++  java
  • Codeforces 222B 数组行列交换操作

    /*做完这题发现自己好水,太伤人了。。。。

    不过还是学到一些,如果直接暴力模拟的话肯定是TLM。。

    所以要用虚拟数组来分别保存当前数组的每行没列在初始数组中的位置。。。*/

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    #define max 1000+5
    int a[max][max];
    int r[max],c[max];

    int main()
    {
        int n,m,k;
        while(~scanf("%d%d%d",&n,&m,&k))
        {
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    scanf("%d",&a[i][j]);
                }
                r[i]=i;
            }
            for(int j=1;j<=m;j++)
            {
                c[j]=j;
            }
            while(k--)
            {
                getchar();
                char cc;
                int x,y;
                scanf("%c %d %d",&cc,&x,&y);
                if(cc=='r')
                {
                   swap(r[x],r[y]);
                   //r[x]^=r[y];r[y]^=r[x];r[x]^=r[y];         //本来想用位操作提点速,泥煤,没想到反而慢了,不知为什么
                }
                else if(cc=='c')
                {
                    swap(c[x],c[y]);
                   //  c[x]^=c[y];c[y]^=c[x];c[x]^=c[y];
                }
                else
                {
                    printf("%d ",a[r[x]][c[y]]);
                }
            }
        }
    }

  • 相关阅读:
    Windows中Lua环境配置记录
    《Programming in Lua 3》读书笔记(四)
    《Programming in Lua 3》读书笔记(三)
    《Programming in Lua 3》读书笔记(一)
    C++中的struct
    POJ 1080 Human Gene Functions
    POJ 3176 Cow Bowling
    POJ 2533 Longest Ordered Subsequence
    POJ 1260 Pearls
    POJ 1836 Alignment
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3703278.html
Copyright © 2011-2022 走看看