码迷,mamicode.com
首页 > 其他好文 > 详细

hihoCoder 1632 Secret Poems(ACM-ICPC北京赛区2017网络同步赛)

时间:2017-11-20 21:53:36      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:because   ble   wro   stand   rod   else   ima   时间   pre   

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

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.

输入

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.

输出

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

样例输入
5
THSAD 
IIVOP 
SEOOH 
RGETI 
YMINK
2
AB
CD
4
ABCD
EFGH
IJKL
MNOP
样例输出
THISI
POEMS
DNKIA
OIHTV
OGYRE
AB
DC
ABEI
KHLF
NPOC
MJGD

暴力模拟,头都模烂了,题意很简单:将一串字符按图一的规律排列,让你输出将这串字符按图二的规律排会是怎样的,
没想太多,直接模拟,按1的规律将原字符串求出来,然后再按2的规律输出。
变成原串的时候i,j写反了,查了一万年的错,然后终于没问题了,将原串按2规律输出的时候,又把赋值用的=手贱写成了==,。。。。。再次查了一万年的错。

变成原串的时候可以自己模拟下4*4的和题目给的5*5的一比,就会发现取值的顺序和奇偶有关,只要判断下奇偶值就可以求出他的顺序就可以了,
最后按2规律输出的时候,没想到什么好的办法,就直接强行模拟他的过程,并标记走过的路,就可以了,不过这个思路应该很智障。。

代码是真的很丑。。。心态写崩了。 突然看到这道题第一个过的只用了六分钟。。emmmmmm。。。。我果然是个辣鸡


实现代码:
 #include<bits/stdc++.h>
 using namespace std;
const int M = 110;
 int main()
 {
     int n;
     char a[M][M],b[10050];
    while(cin>>n){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                cin>>a[i][j];
            }
        }
        int k = 1;
        for(int i=1;i<=n;i++){
            int i1 = i;
            if(i1%2==1){
                for(int j=0;j<i1;j++){
                    b[k++] = a[i1-j][1+j];
                    //cout<<b[k-1]<<" ";
                }
            }
            else{
                for(int j=0;j<i1;j++){
                    b[k++] = a[j+1][i1-j];
                    //cout<<j+1<<" "<<i1-j<<" "<<a[j+1][i1-j]<<endl;
                }
            }
        }
        //for(int i=1;i<=n*n;i++)
            //cout<<b[i];
        //  cout<<endl;
        if(n%2==1){
            for(int i=2;i<=n;i++){
                if(i%2==0){
                    for(int j=0;j<=n-i;j++){
                        b[k++] = a[i+j][n-j];
                    }
                }
                else{
                    for(int j=0;j<=n-i;j++){
                        b[k++] = a[n-j][i+j];
                    }
                }
            }
        }
        else{
             for(int i=2;i<=n;i++){
                if(i%2==1){
                    for(int j=0;j<=n-i;j++){
                        b[k++] = a[i+j][n-j];
                    }
                }
                else{
                    for(int j=0;j<=n-i;j++){
                        b[k++] = a[n-j][i+j];
                    }
                }
            }
        }
        /*for(int i=1;i<=n*n;i++)
            cout<<b[i];
        cout<<endl;*/
        k=1;
        int x=1,y=1;
        int vis[110][110];
        int c[10050];
        memset(vis,0,sizeof(vis));
        memset(a,0,sizeof(a));
        while(1){
            //cout<<x<<endl;
            for(int i=1;i<=n;i++){
                if(vis[x][i]==0){
                    //cout<<x<<" "<<i<<endl;
                    vis[x][i]=1;   //就是这里卡了一万年的 == 。
                    //cout<<vis[x][i];
                    a[x][i]=b[k++];
                    //cout<<a[x][i];
                    y = i;
                }
            }
            for(int i=2;i<=n;i++){
                if(vis[i][y]==0){
                    vis[i][y]=1;
                    a[i][y]=b[k++];
                    //cout<<a[i][y];
                    x = i;
                }
            }
            //cout<<endl;
            for(int i=n-1;i>=1;i--){
                if(vis[x][i]==0){
                    vis[x][i] = 1;
                    a[x][i] = b[k++];
                    //cout<<a[x][i];
                    y=i;
                }

            }
            //cout<<endl;
            for(int i=n-1;i>=2;i--){
                if(vis[i][y]==0){
                    vis[i][y]=1;
                    a[i][y] = b[k++];
                    //cout<<a[i][y];
                    x=i;
                }
            }
            //cout<<endl;
            if(k==n*n+1) break;
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                cout<<a[i][j];
            }
            cout<<endl;
        }
    }
}

 





hihoCoder 1632 Secret Poems(ACM-ICPC北京赛区2017网络同步赛)

标签:because   ble   wro   stand   rod   else   ima   时间   pre   

原文地址:http://www.cnblogs.com/kls123/p/7868075.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!