2017ACM-ICPC亚洲区域赛北京站 F.Secret Poems(模拟)
来源:互联网 发布:倍福plc编程语言 编辑:程序博客网 时间:2024/05/16 12:10
描述
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.
样例输入
5THSAD IIVOP SEOOH RGETI YMINK2ABCD4ABCDEFGHIJKLMNOP
样例输出
THISIPOEMSDNKIAOIHTVOGYREABDCABEIKHLFNPOCMJGD
思路
题意很简单,看那两张图就可以明白,先用第一张图的方式把图片中的序列读出来,再用类似蛇形填数的方法,把这一串序列填进去,然后输出填后的图就可以
代码
#include <bits/stdc++.h>using namespace std;#define mem(a,b) memset(a,b,sizeof(a))const int N=100+20;int n;char mp1[N][N];int mp2[N][N];string init(){ string s=""; s+=mp1[1][1]; int x=1,y=1,op=0; while(!(x==n&&y==n)) { if(x==1&&op==0) { if(y+1<=n) y++; else x++; op=1; } else if(y==1&&op==1) { if(x+1<=n) x++; else y++; op=0; } else { if(op==1) { if(x+1<=n&&y-1>=1) { x++; y--; op=1; } else { y++; op=0; } } else if(op==0) { if(x-1>=1&&y+1<=n) { x--; y++; op=0; } else { x++; op=1; } } } s+=mp1[x][y]; } return s;}void solve(){ mem(mp2,0); int x=0,y=0,cnt; cnt=mp2[x][y]=1; while(cnt<n*n) { while(y+1<n&&!mp2[x][y+1]) mp2[x][++y]=++cnt; while(x+1<n&&!mp2[x+1][y]) mp2[++x][y]=++cnt; while(x-1>=0&&!mp2[x-1][y]) mp2[--x][y]=++cnt; while(y-1>=0&&!mp2[x][y-1]) mp2[x][--y]=++cnt; }}int main(){ while(~scanf("%d",&n)) { for(int i=1; i<=n; i++) scanf("%s",mp1[i]+1); string s=init(); solve(); for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { printf("%c",s[mp2[i][j]-1]); } puts(""); } } return 0;;}
- 2017ACM-ICPC亚洲区域赛北京站 F.Secret Poems(模拟)
- Secret Poems 2017ACM-ICPC北京赛区/hihoCoder1632
- ACM-ICPC北京赛区2017网络同步赛(题目6 : Secret Poems)
- ACM-ICPC北京赛区2017网络同步赛 题目6 : Secret Poems
- 2016ACM亚洲区域赛北京站游记
- 2016 ACM-ICPC 亚洲区域赛北京站E题 What a Ridiculous Election (BFS预处理)
- 2017ACM-ICPC亚洲区域赛西安站热身赛 B. A+B or A-B(模拟)
- 2014ACM/ICPC亚洲区北京站-重现赛
- 2014ACM/ICPC亚洲区北京站-重现赛 D(hdu5115)
- 2016ACM/ICPC亚洲区北京站现场赛直播地址
- ICPC区域赛北京站
- 2017 ACM/ICPC 亚洲区域赛 青岛赛区
- 2017 ACM-ICPC 亚洲区域赛【西安站网赛】Maximum Flow
- 2017 ACM-ICPC亚洲区域赛 西安站总结
- 2017ACM-ICPC亚洲区域赛(西安站)
- 2017ACM-ICPC亚洲区域赛(青岛站)
- 2014ACM/ICPC亚洲区北京站
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区) F Islands
- 星期选择器
- Unity UGUI中RectTransfrom中锚点(Anchor)、中心(Pivot)、Rect及坐标分析
- 记一道USB流量分析CTF题
- Spring Boot学习笔记
- Winodws x64系统服务调用的那头4个参数
- 2017ACM-ICPC亚洲区域赛北京站 F.Secret Poems(模拟)
- Ubuntu安装scrapy
- Linux平台安装opencv3.1.0
- 如何在SpringBoot中监控执行引擎(actuator)?
- PHP邮件发送代码实现
- Leetcode 714
- Handler源码原理分析
- Choosing Capital for Treeland (树形dp)
- LeetCode-Split Linked List in Parts