#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. python字符串的方法介绍

    博文取自鱼C论坛文章: http://bbs.fishc.com/forum.php?mod=viewthread&tid=38992&extra=page%3D1%26filter% ...

  2. LSD_SLAM(一)运行数据集

    虽然按照作者的推荐使用的是OpenCV 2.4.8,但编译依然通不过,一直有错误: 因为lsd_slam是2014年出的,用的ros编译系统不是catkin而是rosbuild,有一些不理解的地方. ...

  3. EF Core ThenInclude 2.0自动完成提示有误,坑了一下

    只要代码正确,可以编译运行的... https://github.com/dotnet/roslyn/issues/8237

  4. web漏洞原理 (需要每周更新此篇文章)

    SQL注入攻击简介 结构化查询语言SQL是用来和关系数据库进行交互的文本语言.它允许用户对数据进行有效的管理,包含了对数据的查询.操作.定义和控制等几个方面,例如向数据库写入.插入数据,从数据库读取数 ...

  5. Django模型与创建管理员用户

    默认情况下, 配置使用SQLite:

  6. Response对象及常用方法

    void addCookie(Cookie cookie)给客户端添加一个Cookie对象,以保存客户端的信息 void addDateHeader(String name,long value) 添 ...

  7. flex布局笔记

    flex布局: 容器: 容器主轴方向: 项目的主轴对齐方式: space-between:两端对齐,项目之间的间隔都相等. space-around:每个项目两侧的间隔相等.所以,项目之间的间隔比项目 ...

  8. leetcode合并区间

    合并区间     给出一个区间的集合,请合并所有重叠的区间. 示例 1: 输入: [[1,3],[2,6],[8,10],[15,18]] 输出: [[1,6],[8,10],[15,18]] 解释: ...

  9. [SHELL]shell中变量的使用

    1.输出变量 : #! /bin/bash my_var=BOB echo $my_var echo "hi,$my_var" echo "the price is \$ ...

  10. (python)leetcode刷题笔记04 Median of Two Sorted Arrays

    4. Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectiv ...