2017 Beijing Network Game F Secret Poems serpentine loop output

Time limit: 1000ms
A single point of time: 1000ms
Memory Limit: 256MB

description

The Yongzheng Emperor (13 December 1678 – 8 October 1735), was the fifth emperor of the Qing dynasty of China. He was a very hard-working ruler. He cracked down on corruption and his reign was known for being despotic, efficient, and vigorous.

Yongzheng couldn’t tolerate people saying bad words about Qing or him. So he started a movement called “words prison”. “Words prison” means literary inquisition. In the famous Zhuang Tinglong Case, more than 70 people were executed in three years because of the publication of an unauthorized history of the Ming dynasty.

In short, people under Yongzheng’s reign should be very careful if they wanted to write something. So some poets wrote poems in a very odd way that only people in their friends circle could read. This kind of poems were called secret poems.

A secret poem is a N×N matrix of characters which looks like random and meaning nothing. But if you read the characters in a certain order, you will understand it. The order is shown in figure 1 below:

            figure 1                                                           figure 2

Following the order indicated by arrows, you can get “THISISAVERYGOODPOEMITHINK”, and that can mean something.

But after some time, poets found out that some Yongzheng’s secret agent called “Mr. blood dripping” could read this kind of poems too. That was dangerous. So they introduced a new order of writing poems as shown in figure 2. And they wanted to convert the old poems written in old order as figure1 into the ones in new order. Please help them.

Entry

There are no more than 10 test cases.

For each test case:

The first line is an integer N( 1 <= N <= 100), indicating that a poem is a N×N matrix which consist of capital letters.

Then N lines follow, each line is an N letters string. These N lines represent a poem in old order.

Export

For each test case, convert the poem in old order into a poem in new order.

Sample input
5 
THSAD 
IIVOP 
SEOOH 
RGETI 
YMINK 
2 
AB 
CD 
4 
ABCD 
EFGH 
IJKL 
MNOP
Sample Output
THISI 
of POEMS 
DNKIA 
OIHTV 
OGYRE 
AB 
DC 
ABEI 
KHLF 
NPOC 
MJGD 

meaning of the title: the raw data in Figure a way to save, and now you want to save the raw data by Figure II mode and output

Solution:
the first observation of a map, extract the original data. Observation know, the data are in accordance with sub-diagonal, either up or down the stored sequence, so that for (i = 0; i < 2 * n; i ++) cycle simulation.
In the observation, that when i is odd downward direction, upward direction is an even number, if it is determined to
look at Figure II is a serpentine loop, each square is the walk around, the starting point of each circle is on the main diagonal, starting coordinates (x, y) are each completed a revolution plus one, and the side of the square will be reduced by two.
Walk around again to the analog four directions

big brother code
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#include<vector>
#include<utility>
#include<map>
#include<queue>
#include<set>
#define mx 0x3f3f3f3f
#define ll long long
#define maxn 105
using namespace std;
intANS, n, m, T, X;
 char STR [MAXN] [MAXN];
 String S;
 void DFS ( int X, int Y, int n-, int T) // (X, Y) coordinates of the starting point, n being side of the square go 
{
     IF (n-< . 1 )
         return ;
     for ( int I = Y; I <+ n-Y; I ++) // go right 
        STR [X] [I] = S [++ T ];
     for ( int I = X + . 1 ; I <+ n-X; I ++) // go down 
        STR [I] [Y + N- . 1 ] = S [++ T ];
     for( Int I = N- Y + 2 ; I> = Y; i--) // go left 
        STR [N- + X . 1 ] [I] = S [++ T ];
     for ( int I = X + N- 2 ; I> X; i--) // go up 
        STR [I] [Y] = S [++ T ]; 
    DFS (X + . 1 , Y + . 1 , N- 2 , T); // completed a revolution after , starting along the main diagonal of +1, the lap side length -2 
}
 int main () 
{ 
    the while (CIN >> n-) 
    { 
        s.clear (); 
        for ( int I = 0 ; I <n-; i ++ )
            CIN >> STR [I];
         for ( int I = 0 ; I < 2 * n-; I ++) // cycle diagonal 
        {
             IF (% I 2 ) // odd time to go down 
            {
                 for ( int J I =; J> = 0 ; J, )
                     IF (ij of <&& n-J < n-) 
                        S + STR = [ij of ] [J]; 
            } 
            the else // the even go up 
            {
                 for ( int J =0; j<=i; j++)
                    if(i-j<n&&j<n)
                        s+=str[i-j][j];
            }
        }
        dfs(0,0,n,0);
        for(int i=0; i<n; i++)
            cout<<str[i]<<endl;
    }
    return 0;
}

 

 
   

Guess you like

Origin www.cnblogs.com/-citywall123/p/11350673.html