时间限制: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. float与double的范围和精度以及大小非零比较

    1. 范围  float和double的范围是由指数的位数来决定的.  float的指数位有8位,而double的指数位有11位,分布如下:  float:  1bit(符号位) 8bits(指数位) ...

  2. 微信OAuth2.0网页授权接口

    微信OAuth2.0网页授权接口 微信OAuth2.0网页授权接口的thinkphp实现版本号.主要实现了oauth网页受权,以及部分其它接口. 用法 为什么用OAuth2.0受权? 通过OAuth2 ...

  3. 2《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——操作文件

    已经学习了基本的命令,现在是时候学习操作文件了,这也是命令行的重要任务.还是基于本教程的事先规定,本教程是入门级的,不要求熟悉类似编辑文本的程序(这些文本编辑程序,将在下个系列教程中介绍, Learn ...

  4. 20155338《网络对抗》Exp3 免杀原理与实践

    20155338<网络对抗>Exp3 免杀原理与实践 实验过程 一.免杀效果参考基准 Kali使用上次实验msfvenom产生后门的可执行文件,上传到老师提供的网址http://www.v ...

  5. HTML 中使 footer 始终处于页面底部

    通常在页面中,需要使页脚 footer 部分始终处于底部.当页面高度不够 100% 时, footer 处于页面最底部,当页面内容高于 100% 时,页脚元素可以被撑到最底部. 方法一:绝对定位 &l ...

  6. winform 保存文件 打开文件 选择文件 字体样式颜色(流 using System.IO;)

    string filePath = ""; private void 保存SToolStripMenuItem_Click(object sender, EventArgs e) ...

  7. 290. Word Pattern【LeetCode by java】

    今天发现LintCode页面刷新不出来了,所以就转战LeetCode.还是像以前一样,做题顺序:难度从低到高,每天至少一题. Given a pattern and a string str, fin ...

  8. 【URLOS应用开发基础】10分钟制作一个nginx静态网站环境应用

    URLOS开发者功能已上线有一段时间了,目前通过部分开发者的使用体验来看,不得不说URLOS在服务器软件开发效率方面确实有着得天独厚的优势,凭借docker容器技术与其良好的应用生态环境,URLOS必 ...

  9. 四种遍历hashMap的方法及比较

    学习怎样遍历Java hashMap及不同方法的性能. // hashMap的遍历 public void testHashMap() { Map<String, String> map ...

  10. PAT甲题题解-1005. Spell It Right (20)-数位求和,水

    把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 #include <iostream> #include <cstdio> #include <alg ...