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,显然不存在. 如果所有点共 ...
随机推荐
- Beautifulsoap - request 网络爬虫 (转)
http://www.cnblogs.com/jiayongji/p/7118939.html (转) python爬虫系列(2)—— requests和BeautifulSoup库的基本用法
- 《Head First 设计模式》[01] 策略模式
<Head First 设计模式>(点击查看详情) 1.写在前面的话 之前在列书单的时候,看网友对于设计模式的推荐里说,设计模式的书类别都大同小异,于是自己就选择了Head First系列 ...
- 20155223 Exp2 后门原理与实践
20155223 Exp2 后门原理与实践 实验预热 一.windows获取Linux shell Windows:使用 ipconfig 命令查看当前机器IP地址. 进入ncat所在文件地址,输入命 ...
- AT24C02跨页写数据
AT24C02 EEPROM的写数据分为:字节写数据模式和页写数据模式:字节写就是一个地址一个数据的写,页写是连续写数据,一个地址多个数据的写,但是页写不能自动跨页,如果超出一页长度,超出的数据会覆盖 ...
- tkinter 弹出窗口 传值回到 主窗口
有些时候,我们需要使用弹出窗口,对程序的运行参数进行设置.有两种选择 一.标准窗口 如果只对一个参数进行设置(或者说从弹出窗口取回一个值),那么可以使用simpledialog,导入方法: from ...
- HNOI2019 摸鱼记
感觉准备省选时有点浮躁,没有准备联赛时那样认真, 希望能将这次省选当做一个教训吧QAQ. Day -inf 基本上把要学的东西都学了,至少做到了自己心里有底. Day 0 乒乓球室没开差评,打隔膜不带 ...
- Python学习之路(一)之Python基础1
目录 Python基础初识 1.Python介绍 1.1.Python简介 1.2.Python特点 1.3.Python应用领域 1.4.Python解释器的种类 2.Python基础初识 2.1. ...
- MongoDB的账户与权限管理及在Python与Java中的登录
本文主要介绍了MongoDB的账户新建,权限管理(简单的),以及在Python,Java和默认客户端中的登陆. 默认的MongoDB是没有账户权限管理的,也就是说,不需要密码即可登陆,即可拥有读写的权 ...
- 【Unity Shader】(三) ------ 光照模型原理及漫反射和高光反射的实现
[Unity Shader](三) ---------------- 光照模型原理及漫反射和高光反射的实现 [Unity Shader](四) ------ 纹理之法线纹理.单张纹理及遮罩纹理的实现 ...
- PAT甲题题解-1042. Shuffling Machine (20)-模拟
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789205.html特别不喜欢那些随便转载别人的原创文章又不给 ...