时间限制: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 题意:原始数据按图一方式保存,现在要你将原始数据按图二方式保存并输出 题解:
先观察图一,提取原始数据。观察知道,数据都是按照副对角线,要么向上,要么向下的顺序保存的,所以for(i=0;i<2*n;i++)循环模拟。
在观察,发现当i为奇数时方向向下,偶数时方向向上,所以if判断即可
再看图二,是一个蛇形回路,每次走一圈都是正方形,每一圈的起点都是在主对角线上,起点坐标(x,y)每走完一圈都会加一,并且正方形的边长都会减小2。
走一圈分四个方向模拟一遍即可 大佬的代码
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#include<vector>
#include<utility>
#include<map>
#include<queue>
#include<set>
#define mx 0x3f3f3f3f
#define ll long long
#define maxn 105
using namespace std;
int ans,n,m,t,x;
char str[maxn][maxn];
string s;
void dfs(int x,int y,int n,int t)//(x,y)是起点坐标,n是要走正方形的边长
{
if(n<)
return;
for(int i=y; i<y+n; i++)//向右走
str[x][i]=s[t++];
for(int i=x+; i<x+n; i++)//向下走
str[i][y+n-]=s[t++];
for(int i=y+n-; i>=y; i--)//向左走
str[x+n-][i]=s[t++];
for(int i=x+n-; i>x; i--)//向上走
str[i][y]=s[t++];
dfs(x+,y+,n-,t);//走完一圈之后,起点沿着主对角线+1,下一圈的边长-2
}
int main()
{
while(cin>>n)
{
s.clear();
for(int i=; i<n; i++)
cin>>str[i];
for(int i=; i<*n; i++)//对角线上循环
{
if(i%)//奇数的时候向下走
{
for(int j=i; j>=; j--)
if(i-j<n&&j<n)
s+=str[i-j][j];
}
else//偶数向上走
{
for(int j=; j<=i; j++)
if(i-j<n&&j<n)
s+=str[i-j][j];
}
}
dfs(,,n,);
for(int i=; i<n; i++)
cout<<str[i]<<endl;
}
return ;
}

2017北京网络赛 F Secret Poems 蛇形回路输出的更多相关文章

  1. Hiho 1232 北京网络赛 F Couple Trees

    给两颗标号从1...n的树,保证标号小的点一定在上面.每次询问A树上的x点,和B树上的y点同时向上走,最近的相遇点和x,y到这个点的距离. 比赛的时候想用倍增LCA做,但写渣了....后来看到题解是主 ...

  2. 2015北京网络赛 F Couple Trees 暴力倍增

    Couple Trees Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/123 ...

  3. (中等) Hiho 1232 Couple Trees(15年北京网络赛F题),主席树+树链剖分。

    "Couple Trees" are two trees, a husband tree and a wife tree. They are named because they ...

  4. 2017西安网络赛 F

    f(cos(x))=cos(n∗x) holds for all xx. Given two integers nn and mm, you need to calculate the coeffic ...

  5. hihoCoder #1388 : Periodic Signal ( 2016 acm 北京网络赛 F题)

    时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal processing. He has a device w ...

  6. acm 2015北京网络赛 F Couple Trees 主席树+树链剖分

    提交 题意:给了两棵树,他们的跟都是1,然后询问,u,v 表 示在第一棵树上在u点往根节点走 , 第二棵树在v点往根节点走,然后求他们能到达的最早的那个共同的点 解: 我们将第一棵树进行书链剖,然后第 ...

  7. 2017北京网络赛 Bounce GCD加找规律

    题目链接:http://hihocoder.com/problemset/problem/1584 题意:就是求一个小球从矩阵的左上角,跑到矩形的右下角不能重复经过的格子,小球碰到墙壁就反射. 解法: ...

  8. HDU 5037 Frog(2014年北京网络赛 F 贪心)

    开始就觉得有思路,结果越敲越麻烦...  题意很简单,就是说一个青蛙从0点跳到m点,最多可以跳l的长度,原有石头n个(都仅表示一个点).但是可能跳不过去,所以你是上帝,可以随便在哪儿添加石头,你的策略 ...

  9. acm 2015北京网络赛 F Couple Trees 树链剖分+主席树

    Couple Trees Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/123 ...

随机推荐

  1. java面试(一)

    一.java基础 1.JDK和JRE的区别? JDK是java的开发环境,JRE是java的运行环境,即编写java程序就一定需要JDK,只是运行java程序只要JRE就足够了. 2.java中==和 ...

  2. 「CF1313C Skyscrapers」

    题目大意 给出一个长度为 \(N\) 的序列 \(a\) 需要构造出一个长度为 \(N\) 的序列 \(h\) 使得 \(\forall i \in \{1,2,\ldots ,N\} h_i \le ...

  3. php 高级 多台web服务器共享session的方法

    解决多台web服务器共享session的问题,至少有以下三种方法:   一.将本该保存在web服务器磁盘上的session数据保存到cookie中 即用cookie会话机制替代session会话机制, ...

  4. linux操作系统及内核

    自己的一点总结,把知识重新编码~ 一.操作系统概述 在Richard Stevens的unix环境高级编程中这样定义“它控制计算机硬件资源,提供程序运行环境.一般而言我们称这种软件为内核(kernel ...

  5. 时间复杂度Big O以及Python 内置函数的时间复杂度

    声明:本文部分内容摘自 原文 本文翻译自Python Wiki 本文基于GPL v2协议,转载请保留此协议. 本页面涵盖了Python中若干方法的时间复杂度(或者叫"大欧",&qu ...

  6. updataxml报错注入

    // take the variables//接受变量 // //也就是插入post提交的uname和passwd,参见:https://www.w3school.com.cn/sql/sql_ins ...

  7. c# 字符串比较优化

    一,优化举例 二,浅谈StringComparison 三,C# CultureInfo 类 各国语言对应的区域性名称 一,优化举例 我们在写程序的时候,经常会用到字符串对比.例如:if(IsChec ...

  8. Servlet 设置字符编码filter

    filter package common; import javax.servlet.*; import java.io.IOException; public class EncodingFilt ...

  9. Thymeleaf的内置属性(转)

    原文链接: http://somefuture.iteye.com/blog/2253761 Thymeleaf是另一个Java视图模板引擎,使用上和FreeMarker各有千秋,不了解的可以从其他博 ...

  10. 「Luogu P3078 [USACO13MAR]扑克牌型Poker Hands」

    本题有\(O(N)\)的优秀做法,但是因为在考场上不一定能想到,就来分享一种\(O(N\log_2N)\)的做法.虽然有点慢,但是可以过. 前置芝士 线段树:提高组及以上必备内容,不会的同学可以学习一 ...