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; }
  • 相关阅读:
    Python爬虫之-动态网页数据抓取
    Python爬虫之 正则表达式和re模块
    Python爬虫 XPath语法和lxml模块
    Python 多线程爬虫
    PAT 1037 在霍格沃茨找零钱
    PAT 1033 旧键盘打字
    PAT 1019 数字黑洞
    PAT 1057 数零壹
    PAT 1026 程序运行时间
    PAT 1023 组个最小数
  • 原文地址:https://www.cnblogs.com/Tianwell/p/11552264.html
Copyright © 2011-2022 走看看