#1632 : Secret Poems

时间限制: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
/*
模拟
*/ #include <bits/stdc++.h> #define MAXN 123 using namespace std; int n;
char str[MAXN][MAXN];
string s;
int x,y;
int pos;
int dir[][]={,,,-,,,-,};
int dir2[][]={,,,,,-,-,}; bool vis[MAXN][MAXN]; bool ok(int x,int y){
if(x<||x>=n||y<||y>=n||vis[x][y]==true)
return false;
return true;
} inline void init(){
memset(str,'\0',sizeof str);
memset(vis,false,sizeof vis);
pos=;
s="";
x=;
y=;
} int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
init();
for(int i=;i<n;i++)
scanf("%s",str[i]);
while(true){
vis[x][y]=true;
s+=str[x][y];
bool flag=false;
int i;
for(i=;i<;i++){
int fx=x+dir[(pos+i)%][];
int fy=y+dir[(pos+i)%][];
if(ok(fx,fy)==true){
flag=true;
break;
}
}
if(flag==false)
break;
pos=(pos+i)%;
x+=dir[pos][];
y+=dir[pos][];
if(pos==||pos==)
pos=(pos+)%;
}
memset(vis,false,sizeof vis);
x=;y=;
pos=;
int cur=;
while(true){
vis[x][y]=true;
str[x][y]=s[cur++];
bool flag=false;
int i;
for(i=;i<;i++){
int fx=x+dir2[(pos+i)%][];
int fy=y+dir2[(pos+i)%][];
if(ok(fx,fy)==true){
flag=true;
break;
}
}
if(flag==false)
break;
pos=(pos+i)%;
x+=dir2[pos][];
y+=dir2[pos][];
}
for(int i=;i<n;i++){
for(int j=;j<n;j++){
printf("%c",str[i][j]);
}
printf("\n");
}
}
return ;
}

2017 ICPC beijing F - Secret Poems的更多相关文章

  1. 2017北京网络赛 F Secret Poems 蛇形回路输出

    #1632 : Secret Poems 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The Yongzheng Emperor (13 December 1678 – ...

  2. 2017 ICPC beijing E - Cats and Fish

    #1631 : Cats and Fish 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are many homeless cats in PKU camp ...

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

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The Yongzheng Emperor (13 December 1678 – 8 October 1735), was ...

  4. 【恐怖的数组模拟】Secret Poems - HihoCoder - 1632

    Secret Poems - HihoCoder - 1632 图一 图二 Following the order indicated by arrows, you can get “THISISAV ...

  5. 2017 ACM/ICPC 沈阳 F题 Heron and his triangle

    A triangle is a Heron’s triangle if it satisfies that the side lengths of it are consecutive integer ...

  6. 2017 icpc 沈阳网络赛

    cable cable cable Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. Bumped! 2017 ICPC North American Qualifier Contest (分层建图+dijstra)

    题目描述 Peter returned from the recently held ACM ICPC World finals only to find that his return flight ...

  8. 2017 ICPC 广西邀请赛1004 Covering

    Covering Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. 2017 ICPC区域赛(西安站)--- J题 LOL(DP)

    题目链接 problem description 5 friends play LOL together . Every one should BAN one character and PICK o ...

随机推荐

  1. Web服务器、Web容器、Application服务器、反向代理服务器的区别与联系

    在Web开发中,经常会听到Web服务器(Web Server).Web容器(Web Container).应用服务器(Application Server).反向代理服务器(Reverse Proxy ...

  2. 开发Windows服务

          在开发Windows服务时需要注意一点,如果在开发完成后,需要通过命令来进行安装的,那么在开发的时候,需要在服务类上面添加一个安装文件.如下图:               添加完成后,就 ...

  3. Awesome Django

     Awesome Django    If you find Awesome Django useful, please consider donating to help maintain it. ...

  4. hdu2099整除的尾数(暴力 省赛)

    整除的尾数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. OSG-OSG中的observer_ptr指针

    看array大神的CookBook后一些感想,在代码上添加了一些注释,也对源码做了一些研读,记录下学习的过程. CookBook中第一个例子就是observer_ptr指针,这个指针和它的名字一样,就 ...

  6. selenium--特殊元素定位

    该篇博客总结特殊元素(select.radio\checkbox.时间控件.文件上传.图片验证码.模拟鼠标操作.Js 或 JQuery调用)操作. 1.select @Test public void ...

  7. Windowserver2012部署always on

    1.首先,安装域环境 IP设置 域服务安装 如果建立域配置时出现 administrator账户密码不符合要求错误: cmd运行命令: net user administrator /password ...

  8. github项目切换远程https到ssh通道

    github 切换远程https到ssh通道 github 每个仓库有两类地址:https和ssh通道. https通道获取代码方便,提交过程中每次都需要输入用户名和密码. ssh通道需要提前配置号s ...

  9. BOM / URL编码解码 / 浏览器存储

    BOM 浏览器对象模型 BOM(Browser Object Model) 是指浏览器对象模型,是用于描述这种对象与对象之间层次关系的模型,浏览器对象模型提供了独立于内容的.可以与浏览器窗口进行互动的 ...

  10. SIG蓝牙mesh笔记2_mesh组成

    目录 SIG 蓝牙 mesh 组成 mesh网络概述 网络和子网 设备和节点 devices & nodes 入网 mesh中的几个概念 智能插座例子 SIG 蓝牙 mesh 组成 mesh网 ...