ACM-ICPC北京赛区2017网络同步赛 题目6 : Secret Poems
来源:互联网 发布:软件缺陷的生命周期 编辑:程序博客网 时间:2024/05/18 02:37
题目6 : 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:
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>using namespace std;//两个矩阵char A[105][105], B[105][105];//按顺序存取第一个矩阵char C[10005];int cnt;//插入到第二个矩阵时判断转向bool visit[105][105];int main(){ int n; while(cin>>n) { memset(visit, false, sizeof(visit)); for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin>>A[i][j]; cnt = 0; int x = 0; int y = 0; int fax = 1;//1为向上,-1为向下 int s = 0;//是否横向还是斜向 //左上部矩阵存储 while(x != n-1 && y != n-1) { C[cnt++] = A[x][y]; if(x == 0) { if(s == 0) { y++; s = 1; continue; } else { y--; x++; fax = -1; s = 0; continue; } } if(y == 0) { if(s == 0) { x++; s = 1; continue; } else { x--; y++; fax = 1; s = 0; continue; } } if(fax == 1) { x--; y++; } if(fax == -1) { x++; y--; } } s = 1; fax = 1; //右下部矩阵存储 while(x != n-1 || y != n-1) { C[cnt++] = A[x][y]; if(x == n-1) { if(s == 0) { y++; s = 1; continue; } else { y++; x--; fax = 1; s = 0; continue; } } if(y == n-1) { if(s == 0) { x++; s = 1; continue; } else { x++; y--; fax = -1; s = 0; continue; } } if(fax == 1) { x--; y++; } if(fax == -1) { x++; y--; } } C[cnt++] = A[n-1][n-1]; x = y = 0; fax = 1; //转换 for(int i=0; i<cnt; i++) { B[x][y] = C[i]; visit[x][y] = true; if(fax == 1) { if((y+1) <= (n-1) && !visit[x][y+1]) y++; else { fax = 2; x++; } continue; } if(fax == 2) { if((x+1) <= (n-1) && !visit[x+1][y]) x++; else { y--; fax = 3; } continue; } if(fax == 3) { if((y-1) >= 0 && !visit[x][y-1]) y--; else { x--; fax = 4; } continue; } if(fax == 4) { if((x-1) >= 0 && !visit[x-1][y]) x--; else { y++; fax = 1; } continue; } } for(int i=0; i<n; i++) { for(int j=0; j<n; j++) cout<<B[i][j]; cout<<"\n"; } } return 0;}
- ACM-ICPC北京赛区2017网络同步赛(题目6 : Secret Poems)
- ACM-ICPC北京赛区2017网络同步赛 题目6 : Secret Poems
- Secret Poems 2017ACM-ICPC北京赛区/hihoCoder1632
- ACM-ICPC北京赛区2017网络同步赛 题目5 : Cats and Fish【模拟】
- ACM-ICPC北京赛区2015网络同步赛E:Stamps
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum-(线段树)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目1 : Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目1 : Visiting Peking University
- Visiting Peking University 2017ACM-ICPC亚洲区(北京赛区)网络赛题目1
- ACM-ICPC北京赛区(2017)网络赛-题目9 : Minimum(线段树)
- ACM/ICPC北京赛区网络赛
- 2017 ACM-ICPC 亚洲区(北京赛区)网络赛
- 2017 ACM-ICPC 亚洲区(北京赛区)网络赛
- ACM-ICPC北京赛区网络赛2017-minimum(线段树)
- ACM-ICPC 2017南宁赛区网络赛题目题解收集
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum(线段树)
- 2017ACM-ICPC亚洲区域赛北京站 F.Secret Poems(模拟)
- 2014 ACM/ICPC 北京赛区网络赛解题报告汇总
- thymeleaf模板引擎之基本语法
- Swift-如何写share safari camera
- 理解 module.exports和node.js的exports
- Python 练习实例4
- JavaScript中使用html音频对象audio
- ACM-ICPC北京赛区2017网络同步赛 题目6 : Secret Poems
- .deb软件包的安装和软件的卸载
- 对话框Diglog的应用
- JUnit笔记--JUnit中的断言
- C#面试知识点小结
- 微信小程序 post 发送数据 终极大法
- 《STL源码剖析》之 ROUND_UP()实现原理详解
- SDUToj
- 编译原理复习1