2017 ICPC beijing F - Secret Poems
#1632 : Secret Poems
描述
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的更多相关文章
- 2017北京网络赛 F Secret   Poems 蛇形回路输出
		
#1632 : Secret Poems 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The Yongzheng Emperor (13 December 1678 – ...
 - 2017 ICPC beijing E - Cats and Fish
		
#1631 : Cats and Fish 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are many homeless cats in PKU camp ...
 - hihoCoder 1632 Secret Poems(ACM-ICPC北京赛区2017网络同步赛)
		
时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The Yongzheng Emperor (13 December 1678 – 8 October 1735), was ...
 - 【恐怖的数组模拟】Secret Poems - HihoCoder - 1632
		
Secret Poems - HihoCoder - 1632 图一 图二 Following the order indicated by arrows, you can get “THISISAV ...
 - 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 ...
 - 2017 icpc 沈阳网络赛
		
cable cable cable Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
 - 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 ...
 - 2017 ICPC 广西邀请赛1004 Covering
		
Covering Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
 - 2017 ICPC区域赛(西安站)--- J题 LOL(DP)
		
题目链接 problem description 5 friends play LOL together . Every one should BAN one character and PICK o ...
 
随机推荐
- bash特性-命令历史命令行编辑
			
bash: GUI:Gnome,KDE,XFCE CLI:sh,csh,bash,ksh,tcsh,zsh shell,子shell tree:查看目录树 pstree:查看进程目录树 bash: 1 ...
 - logstash-input-jdbc and logstash-ouput-jdbc
			
要求通过logstash从oracle中获取数据,然后相应的直接传入mysql中去. 基本测试成功的配置文件如下: input { stdin { } jdbc { jdbc_connection_s ...
 - android自动化のadb常用命令(不定期更新)
			
1. adb devices 执行结果是adb为每一个设备输出以下状态信息:序列号(serialNumber) — 由adb创建的使用控制台端口号的用于唯一标识一个模拟器或手机设备的字符串,格式是 & ...
 - Linearize an sRGB texture in Photoshop
			
From:https://forum.unity.com/threads/bug-with-bypass-srgb-sampling.282469/
 - Java开发工程师(Web方向) - 02.Servlet技术 - 第3章.Servlet应用
			
第3章.Servlet应用 转发与重定向 转发:浏览器发送资源请求到ServletA后,ServletA传递请求给ServletB,ServletB生成响应后返回给浏览器. 请求转发:forward: ...
 - 【20180808模拟测试】T2 k-斐波那契
			
描述 k-斐波拉契数列是这样的 f(0)=k;f(1)=k;f(n)=(f(n-1)+f(n-2))%P(n>=2); 现在我们已经知道了f(n)=1,和P: k的范围是[1,P); 求k的所有 ...
 - github项目切换远程https到ssh通道
			
github 切换远程https到ssh通道 github 每个仓库有两类地址:https和ssh通道. https通道获取代码方便,提交过程中每次都需要输入用户名和密码. ssh通道需要提前配置号s ...
 - 单元测试模块unittest使用学习
			
工作原理: unittest中最核心的四个概念是:test case, test suite, test runner, test fixture. 一个TestCase的实例就是一个测试用例.什么是 ...
 - Office 365 E3功能
			
本文简要总结了Office 365E3的功能
 - Python3 下安装python-votesmart
			
在python2下安装python-smart还比较容易,而python3中由于很多函数库的变化直接使用python setup.py install 命令来安装的话会导致错误,而导致错误的原因就是p ...