【HDOJ】1987 Decoding
简单搜索。
/* hdoj 1987 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std; char s[];
char map[][];
bool visit[][];
int n, m, len;
int dir[][] = {
,, ,, ,-, -,
}; // right down left up bool check(int x, int y) {
return x< || x>=n || y< || y>=m;
} void solve() {
int i, j, k, tmp;
int d = ;
int t = n*m/;
int x, y, xx, yy; len = ;
memset(visit, false, sizeof(visit)); x = , y = -;
while (t--) {
k = ;
tmp = ;
while (k) {
xx = x + dir[d][];
yy = y + dir[d][];
if (check(xx, yy) || visit[xx][yy]) {
d = (d+) & ;
continue;
}
visit[xx][yy] = true;
tmp = (tmp<<) + map[xx][yy]-'';
--k;
x = xx;
y = yy;
}
if (tmp == )
s[len++] = ' ';
else
s[len++] = tmp + 'A' - ;
}
} int main() {
int t, tt;
int i, j, k; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif scanf("%d", &t);
for (tt=; tt<=t; ++tt) {
scanf("%d %d %s", &n, &m, s);
k = ;
for (i=; i<n; ++i)
for (j=; j<m; ++j)
map[i][j] = s[k++];
solve();
i = len - ;
while (s[i] == ' ')
--i;
s[i+] = '\0';
i = ;
while (s[i] == ' ')
++i;
printf("%d %s\n", tt, s+i);
} return ;
}
【HDOJ】1987 Decoding的更多相关文章
- 【dfs】Sequence Decoding
Sequence Decoding 题目描述 The amino acids in proteins are classified into two types of elements, hydrop ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
随机推荐
- Spring AOP + AspectJ Annotation Example---reference
In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...
- 『零行代码』解决键盘遮挡问题(iOS)
关注仓库,及时获得更新:iOS-Source-Code-Analyze https://github.com/draveness/iOS-Source-Code-Analyze Follow: Dra ...
- Bash远程文件传输命令scp
备份远程文件(远程——>本地) scp -r 远程用户名@ip:文件绝对路径 本地绝对路径 还原远程文件(本地——>远程) scp -r 本地路径 远程用户名@ip:远程绝对路径 如果SS ...
- 使用Java BigDecimal进行精确运算
首先我们先来看如下代码示例: public class Test_1 { public static void main(String[] args) { System.out ...
- zabbix 基于JMX的Tomcat监控
zabbix 基于JMX的Tomcat监控 一.环境 ubuntu14.04 LTS Java 1.7.0 zabbix 2.4.5 二.安装配置 1.安装JavaGateway 在ubuntu14. ...
- C#和asp.net中链接数据库中 参数的几种传递方法
#region 参数传递方法第一种 //参数设置方法(第一种) //SqlParameter sp = new SqlParameter("@Name", str_Name); / ...
- 获取当前页面的url
var url = window.location.href; var b = url.substring(url.lastIndexOf('/')+1, url.length);
- SpringMVC4+thymeleaf3的一个简单实例(篇五:页面和MySql的数据交互-展示以及存储)
这一篇将介绍怎样把页面数据保存的MySQL数据库,并将数据库内容展示到页面上.首先做一个基础工作,添加以下jar到lib:1: mysql-connector-Java-5.1.40-bin.jar ...
- Base64的用法
如果要对一些图片进行保存,把他的文件名变成乱码,不让用户把他删掉,可以用Base64把他删掉用法如下: //获取访问图片的路径 String path=editText.getText().toStr ...
- 根据CreateDirectory递归创建多级目录
分为MFC下的和非MFC下的两种,MFC路径是CString类型的,非MFC的路径是wstring类型的. 下面是MFC下的创建目录: void __fastcall RecursiveDirecto ...