hihoCoder 1632 Secret Poems(ACM-ICPC北京赛区2017网络同步赛)
描述
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网络同步赛)的更多相关文章
- ACM-ICPC北京赛区2017网络同步赛
E: Cats and Fish 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are many homeless cats in PKU campus. T ...
- hihoCoder 1631 Cats and Fish(ACM-ICPC北京赛区2017网络同步赛)
时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are many homeless cats in PKU campus. They are all happy ...
- hihocoder 1584 Bounce (数学 && 规律) ACM-ICPC北京赛区2017网络赛
题意: 给定一副n*m的格子图, 问从左上角的点开始往右下角滑,碰到墙壁就反弹, 碰到角落就停止, 问恰好经过一次的格子有多少个. 如图,恰好经过一次的格子有39个. 分析: 首先要引入两个概念, “ ...
- hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...
- hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...
- hihoCoder 1586 Minimum 【线段树】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1586 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2 ...
- hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum【线段树】
https://hihocoder.com/problemset/problem/1586 线段树操作,原来题并不难..... 当时忽略了一个重要问题,就是ax*ay要最小时,x.y可以相等,那就简单 ...
- 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute
题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...
随机推荐
- Python中 __init__的通俗解释?附修饰器contextmanager的理解
作者:匿名用户链接:https://www.zhihu.com/question/46973549/answer/103805810来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...
- PHP设计模式——訪问者模式
声明:本系列博客參考资料<大话设计模式>,作者程杰. 訪问者模式表示一个作用于某对象结构中的各元素的操作. 它使你能够在不改变各元素类的前提下定义作用于这些元素的新操作. UML类图: w ...
- Cannot connect to the Docker daemon at unix:///var/run/docker.sock.问题解决
出现Cannot connect to the Docker daemon at unix:///var/run/docker.sock时,先用tail -5f /var/log/upstart/do ...
- 20155229《网络对抗技术》Exp9:Web安全基础
实验内容 Webgoat实践下相关实验. 实验步骤 WebGoat: Webgoat是OWASP组织研究出的一个专门进行web漏洞实验的应用品台,这个平台里包含了web中常见的各种漏洞,例如:跨站脚本 ...
- linux & windows下重启oracle
Linux:方法1 用root以ssh登录到linux,打开终端输入以下命令: cd $ORACLE_HOME #进入到oracle的安装目录 dbstart #重启服务器 lsnrctl start ...
- [arm学习]makefile学习总结
makefile不仅仅是一个命令的集合体,其中有一些规则是需要理解掌握的. 首先,了解makefile的规则: //-----------格式---------- 目标 : 依赖1,依赖2 (TAP键 ...
- centos 7 搭建开源堡垒机 Teleport 遇到的问题解决
不得不说 centos7 的环境版本就是高,没有再出现6.5下那些依赖组件的版本支持过低的错误了,所以说现在个人用户还是推荐用7,企业生产环境的话,可能6.5适合一些,至少2年前是这样. 安装过程: ...
- 账户控制器(AccountController)
账户控制器(AccountController) Account控制器提供了登录,注册,忘了密码和电子邮件激活页面功能. Layout模板视图 在Account视图文件夹中单独建设了模板文件: 登录页 ...
- 第一次软件工程作业(One who wants to wear the crown, Bears the crown.)
回顾你过去将近3年的学习经历 1.当初报考的时候,是真正的喜欢计算机这个专业吗? 报考时对于计算机专业只能说不讨厌,也可以认为对其没有任何的感觉. 有一个比我自己还注意我未来的老妈,我的报考只能通过一 ...
- python中魔法方法__init__,__str__,__del__的详细使用方法
1. python中的魔法方法, 类似__init__, __str__等等,这些内置好的特定的方法进行特定的操作时会自动被调用 2. __init__的使用方法 class 类名(object): ...