时间限制: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 暴力模拟,头都模烂了,题意很简单:将一串字符按图一的规律排列,让你输出将这串字符按图二的规律排会是怎样的,
没想太多,直接模拟,按1的规律将原字符串求出来,然后再按2的规律输出。
变成原串的时候i,j写反了,查了一万年的错,然后终于没问题了,将原串按2规律输出的时候,又把赋值用的=手贱写成了==,。。。。。再次查了一万年的错。 变成原串的时候可以自己模拟下4*4的和题目给的5*5的一比,就会发现取值的顺序和奇偶有关,只要判断下奇偶值就可以求出他的顺序就可以了,
最后按2规律输出的时候,没想到什么好的办法,就直接强行模拟他的过程,并标记走过的路,就可以了,不过这个思路应该很智障。。 代码是真的很丑。。。心态写崩了。 突然看到这道题第一个过的只用了六分钟。。emmmmmm。。。。我果然是个辣鸡 实现代码:
 #include<bits/stdc++.h>
using namespace std;
const int M = ;
int main()
{
int n;
char a[M][M],b[];
while(cin>>n){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
cin>>a[i][j];
}
}
int k = ;
for(int i=;i<=n;i++){
int i1 = i;
if(i1%==){
for(int j=;j<i1;j++){
b[k++] = a[i1-j][+j];
//cout<<b[k-1]<<" ";
}
}
else{
for(int j=;j<i1;j++){
b[k++] = a[j+][i1-j];
//cout<<j+1<<" "<<i1-j<<" "<<a[j+1][i1-j]<<endl;
}
}
}
//for(int i=1;i<=n*n;i++)
//cout<<b[i];
// cout<<endl;
if(n%==){
for(int i=;i<=n;i++){
if(i%==){
for(int j=;j<=n-i;j++){
b[k++] = a[i+j][n-j];
}
}
else{
for(int j=;j<=n-i;j++){
b[k++] = a[n-j][i+j];
}
}
}
}
else{
for(int i=;i<=n;i++){
if(i%==){
for(int j=;j<=n-i;j++){
b[k++] = a[i+j][n-j];
}
}
else{
for(int j=;j<=n-i;j++){
b[k++] = a[n-j][i+j];
}
}
}
}
/*for(int i=1;i<=n*n;i++)
cout<<b[i];
cout<<endl;*/
k=;
int x=,y=;
int vis[][];
int c[];
memset(vis,,sizeof(vis));
memset(a,,sizeof(a));
while(){
//cout<<x<<endl;
for(int i=;i<=n;i++){
if(vis[x][i]==){
//cout<<x<<" "<<i<<endl;
vis[x][i]=; //就是这里卡了一万年的 == 。
//cout<<vis[x][i];
a[x][i]=b[k++];
//cout<<a[x][i];
y = i;
}
}
for(int i=;i<=n;i++){
if(vis[i][y]==){
vis[i][y]=;
a[i][y]=b[k++];
//cout<<a[i][y];
x = i;
}
}
//cout<<endl;
for(int i=n-;i>=;i--){
if(vis[x][i]==){
vis[x][i] = ;
a[x][i] = b[k++];
//cout<<a[x][i];
y=i;
} }
//cout<<endl;
for(int i=n-;i>=;i--){
if(vis[i][y]==){
vis[i][y]=;
a[i][y] = b[k++];
//cout<<a[i][y];
x=i;
}
}
//cout<<endl;
if(k==n*n+) break;
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
cout<<a[i][j];
}
cout<<endl;
}
}
}


hihoCoder 1632 Secret Poems(ACM-ICPC北京赛区2017网络同步赛)的更多相关文章

  1. ACM-ICPC北京赛区2017网络同步赛

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

  2. hihoCoder 1631 Cats and Fish(ACM-ICPC北京赛区2017网络同步赛)

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are many homeless cats in PKU campus. They are all happy ...

  3. hihocoder 1584 Bounce (数学 && 规律) ACM-ICPC北京赛区2017网络赛

    题意: 给定一副n*m的格子图, 问从左上角的点开始往右下角滑,碰到墙壁就反弹, 碰到角落就停止, 问恰好经过一次的格子有多少个. 如图,恰好经过一次的格子有39个. 分析: 首先要引入两个概念, “ ...

  4. hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...

  5. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  6. hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...

  7. hihoCoder 1586 Minimum 【线段树】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1586 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2 ...

  8. hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum【线段树】

    https://hihocoder.com/problemset/problem/1586 线段树操作,原来题并不难..... 当时忽略了一个重要问题,就是ax*ay要最小时,x.y可以相等,那就简单 ...

  9. 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute

    题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...

随机推荐

  1. 异常处理简单例子--python

    捕获所有异常 #!/usr/bin/pythona = 10b = 0try: c = a/b print c print 'nothing happen...'#todo: catch all ex ...

  2. FPGA按一下按键,对应端口输出单个脉冲

    对于FPGA的verilog语言,,,规定一个变量不能在多个always中被赋值.但是可以在多个alway块中做判断--结合状态机思想 module state(key,led,clk); input ...

  3. 第三次作业:结对编程--实现表格在APP的导入和显示

    031302517 031302319 ps:共同完成一篇随笔,文章中的第一人称我(517),队友(319) 一.功能分析+实现思路+结队讨论 这里我将功能分析和实现思路还有结对过程中的一些讨论结合在 ...

  4. ubuntu系统中添加DNS服务器地址后诡异消失的解决办法

    今天查看了一下自己电脑里的ubuntu14.04系统,发现无法上网,于是ping了一下百度,出现unknown host,查了一下/etc/resolv.conf中的DNS地址,却发现我之前的修改被清 ...

  5. Octocat,看着喜欢就都下载下来了

    看见github的octocat很喜欢,就用c#写了个程序统统download了,附上一个比较高效的下载程序,以及文末的图片压缩包. 用到了Jumony解析网页. HttpClient client ...

  6. libgdx学习记录11——平铺地图TiledMap

    地图对于游戏场景十分重要,很多游戏都需要对地图进行编辑,可使用TileMap进行编辑并生成对应的tmx格式地图文件. 编辑好后,可通过TmxMapLoader来读取地图文件.可通过一个正交相机Otho ...

  7. Asp.net中汉字转换成为拼音

    1.应用场景 将汉字转换为拼音(eg:"我爱你"--->"WOAINI") 取各个汉字的首字母(eg:"我是中国人"--->&q ...

  8. Android开发者不可或缺的四大工具

    Android开发者不可或缺的四大工具 android以其极强的开放性吸引着世界各地的开发者去开发各种各样的移动应用开发,而各种SDK更是为各个层次的开发者提供了一个可以尽情展示他们专业技能和创造性的 ...

  9. 软件工程第三次作业(One who wants to wear the crown, Bears the crown.)

    最大连续子数组和 题目 给定n个整数(可能为负数)组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a[j]的子段和的最大值.当所给的整数均为负数时定义子段和 ...

  10. java中多态的实现机制

    多态的概念: 简单来说就是事物在运行过程中存在的不同状态,即父类或接口定义的引用变量指向子类或具体实现类的实例对象.程序调用方法在运行期才进行动态绑定,而不是引用变量的类型中定义的方法. 多态存在的前 ...