时间限制: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. MVC 在action拦截器中获取当前进入的控制器和aciton名

    我们在实现了action拦截器以后(继承至System.Web.Mvc.IActionFilter),需要在重写的方法OnActionExecuting中去获得当前进入的控制器和action名称,如何 ...

  2. jqgrid 自定义添加行数据

    一般在设置了自定义按钮后,比如‘添加’按钮,点击添加需要添加一条数据在表格中. 通过jqgrid的方法 addRowData 插入一行数据. //添加一行数据 function addRow() { ...

  3. SQL_sql语言的学习

    关系数据库SQL sql基本功能 SQLde 基本概念 主要知识点 1.外模式包含若干视图和部分基本表 2.模式包含若干基本表 3.内模式包含若干存储文件 4操作对象 基本表:本身独立存在的表,一个关 ...

  4. mac下载、破解、安装webstorm编辑器

    1.进入webstorm官网 http://www.jetbrains.com/webstorm/,点击DOWNLOAD,开始下载webstorm安装包. untitled.png 2.开始安装 双击 ...

  5. 20155302 Exp2 后门原理与实践

    20155302<网络对抗>后门原理与实践 实验要求 1.使用netcat获取主机操作Shell,cron启动 (0.5分) 2.使用socat获取主机操作Shell, 任务计划启动 (0 ...

  6. ElasticSearch入门 第三篇:索引

    这是ElasticSearch 2.4 版本系列的第三篇: ElasticSearch入门 第一篇:Windows下安装ElasticSearch ElasticSearch入门 第二篇:集群配置 E ...

  7. nodejs 监控代码变动实现ftp上传

    被动模式下 //https://www.npmjs.com/package/watch //文件同步功能 var watch = require('watch'); var path = requir ...

  8. 【翻译】给初学者的 Neural Networks / 神经网络 介绍

    本文翻译自 SATYA MALLICK 的  "Neural Networks : A 30,000 Feet View for Beginners" 原文链接: https:// ...

  9. elasticsearch6.6.0安装配置及elasticsearch-head插件安装

    一.最小化安装centos7.6 cat /etc/redhat-release 二.配置网络,可以上外网 三.安装常用命令工具,修改系统时区,校对系统时间,关闭selinux,关闭firewalld ...

  10. mysql数据出现Unknown column 'user_uid' in 'field list' sql错误

    来源:https://blog.csdn.net/gnail_oug/article/details/53606608 在操作mysql数据库时提示com.mysql.jdbc.exceptions. ...