zoukankan      html  css  js  c++  java
  • 2017 Icpc Beijing F

    题意:

    给你一个矩阵,然后你要按照要求进行读取,以及输出 (折线读取,蛇形输出)

    思路:

    找到规律

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    using namespace std;
    typedef long long ll;
    const int maxn = 110;
    char s[maxn][maxn];
    char p[maxn][maxn];
    int vis[maxn][maxn];
    char c[maxn*maxn];
    int x,y,tot,n;
    int cnt;
    int main()
    {
        while(cin>>n)
        {
            memset(s,0,sizeof s);
            memset(p,0,sizeof p);
            memset(c,0,sizeof c);
            for(int i=0; i<n; i++)
                for(int j=0; j<n; j++)
                    cin>>s[i][j];
            p[0][0]=s[0][0];
            x=0;y=0;
            cnt = 0;
    // 折线读取
    for(int i=0; i<2*n; i++) { if(i%2) { for(int j=i; j>=0; j--) if(i-j<n&&j<n) c[cnt++]+=s[i-j][j]; } else { for(int j=0; j<=i; j++) if(i-j<n&&j<n) c[cnt++]+=s[i-j][j]; } } tot=0; while(tot<n*n-1)//紫书上的蛇形填数 { while(y+1<n&&!p[x][y+1])// p[x][++y]=c[++tot]; while(x+1<n&&!p[x+1][y])// p[++x][y]=c[++tot]; while(y-1>=0&&!p[x][y-1])// p[x][--y]=c[++tot]; while(x-1>=0&&!p[x-1][y])// p[--x][y]=c[++tot]; } for(int i=0; i<n; i++) { for(int j=0; j<n; j++) cout<<p[i][j]; cout<<endl; } } return 0; }
  • 相关阅读:
    Java IO2
    Java IO1 复制粘贴文件
    Java superArray2
    17杭州女子专场赛
    组队赛 A Promotions 深搜+逆向思维
    Java处理异常小试
    再谈Dijkstra算法和堆优化
    仿照JAVA vector模型写一个SuperArray
    HDU 2017女生赛04 (变形最短路)
    Gym-100712J 桶排序思想&反向思维
  • 原文地址:https://www.cnblogs.com/Tianwell/p/11552264.html
Copyright © 2011-2022 走看看