hdu 1200 To and Fro(简单模拟或DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1200
To and Fro
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5129 Accepted Submission(s): 3550
t o i o y
h p k n n
e l e a i
r a h s g
e c o n h
s e m o t
n l e w x
Note that Mo includes only letters and writes them all in lower case. In this example, Mo used the character ‘x’ to pad the message out to make a rectangle, although he could have used any letter.
Mo then sends the message to Larry by writing the letters in each row, alternating left-to-right and right-to-left. So, the above would be encrypted as
toioynnkpheleaigshareconhtomesnlewx
Your job is to recover for Larry the original message (along with any extra padding letters) from the encrypted one.
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; char ch[];
char dp[][]; int main ()
{
int n;
while (~scanf("%d",&n),n)
{
scanf("%s",ch);
int x=,y=;
int len=strlen(ch);
for (int i=; i<len; i++)
{
dp[x][y]=ch[i];
if (x%==)
{
y++;
if (y==n)
{
x++;
y--;
}
}
else
{
y--;
if (y==-)
{
x++;
y++;
}
} }
for (int i=; i<n; i++)
{
for (int j=; j<x; j++)
{
printf ("%c",dp[j][i]);
}
}
printf ("\n");
}
return ;
}
第二种模拟代码,详见注释
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int main()
{
int n;
char ch[];
while(scanf("%d",&n),n)
{
scanf("%s",ch);
int l=strlen(ch);
for(int i=;i<n;i++) //i表示第几列
{
for(int j=;j<l;j++) //j表示第几个数
{
if((j/n)%==) //判断奇偶行
{
if((j-i)%n==) //满足第一组的条件
printf("%c",ch[j]);
}
else
{
if((j+i+)%n==) //满足第二组的条件
printf("%c",ch[j]);
}
}
}
printf("\n");
}
return ;
}
hdu 1200 To and Fro(简单模拟或DP)的更多相关文章
- 【HDU 4452 Running Rabbits】简单模拟
两只兔子Tom和Jerry在一个n*n的格子区域跑,分别起始于(1,1)和(n,n),有各自的速度speed(格/小时).初始方向dir(E.N.W.S)和左转周期turn(小时/次). 各自每小时往 ...
- hdu 4414 Finding crosses【简单模拟】
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4414 CSUST:点击打开链接 Finding crosses Time Limit: 2000/1000 ...
- HDU 5268 ZYB loves Score (简单模拟,水)
题意:计算Bestcoder四题的得分. 思路:直接模拟,4项分数直接计算后输出.注意不要低于百分之40的分. //#include <bits/stdc++.h> #include &l ...
- HDU 5059 Help him(简单模拟题)
http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目大意: 给定一个字符串,如果这个字符串是一个整数,并且这个整数在[a,b]的范围之内(包括a,b),那 ...
- HDOJ/HDU 1200 To and Fro(加密解密字符串)
Problem Description Mo and Larry have devised a way of encrypting messages. They first decide secret ...
- HDU - 1200 To and Fro
题意:给定一个,其实是由一个图按蛇形输出而成的字符串,要求按从左到右,从上到下的顺序输出这个图. 分析: 1.把字符串转化成图 2.按要求输出图= = #include<cstdio> # ...
- HDU 4772 Zhuge Liang's Password (简单模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 ...
- (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数<=3,输出剩下的人 )
题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 4509 湫湫系列故事——减肥记II (简单模拟)
题意:一天一共有1440分钟,主人公每天有n件事要做,给出这n件事开始跟结束的时间,然后让你求出,空闲的时间的总分钟数是多少. 解题报告:简单模拟,只要开个一维数组标记那个每个分钟是否是有事的就可以了 ...
随机推荐
- delphi怎样单步调试
在delphi的IDE编辑窗口里,主菜单->Run->Step Over或者主菜单->Run->Trace Into单步调试有两种方式:一种是Step Over,快捷键是F8, ...
- Visual Studio 2013中使用Ribbon For WPF
1.首先需要 下载Ribbon For WPF.目前最新的版本是Microsoft Ribbon for WPF October 2010. 下载 链接: https://www.microsoft. ...
- 【Json】C#格式化JSON字符串
很多时候我们需要将json字符串以 { "status": 1, "sum": 9 }这种方式显示,而从服务端取回来的时候往往是这样 {&quo ...
- RT-thread内核之邮箱
一.邮箱控制块:在include/rtdef.h中 #ifdef RT_USING_MAILBOX /** * mailbox structure */ struct rt_mailbox { str ...
- SocketServer-实现并发处理3
用socketserver创建一个服务的步骤: 1 创建一个request handler class(请求处理类),合理选择StreamRequestHandler和DatagramRequest ...
- NetScaler SNIPs Bound To An Interface Without A VLAN
NetScaler SNIPs Bound To An Interface Without A VLAN https://www.citrix.com/blogs/2014/04/09/work-yo ...
- 【题解】SDOI2017树点涂色
LCT强强!以前总是觉得LCT非常的难懂(当然现在也是的),但实际上它真的是很厉害的一种东西.它是一种动态的链剖分结构,其实就是对于剖分出来的重链使用LCT去进行维护.cut 与 link 两个操作让 ...
- BZOJ4868:[SHOI2017]期末考试——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=4868 题目复制于洛谷:https://www.luogu.org/problemnew/show/P ...
- BZOJ1257:[CQOI2007]余数之和——题解+证明
http://www.lydsy.com/JudgeOnline/problem.php?id=1257 Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod ...
- HDU5115:Dire Wolf——题解+翻译
http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目大意:给n匹狼,每一次攻击可以秒杀一匹狼,但同时会受到这匹狼的a攻击和它相邻两只狼的b攻击. 给定a, ...