【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 ...
随机推荐
- Java基础知识强化之集合框架笔记36:List练习之键盘录入多个数据在控制台输出最大值
1. 键盘录入多个数据,以0结束,要求在控制台输出这多个数据中的最大值 分析: • 创建键盘录入数据对象 • 键盘录入多个数据,我们不知道多少个,所以用集合存储 • 以0结束,这个简单,只要键盘 ...
- poj 1821 Fence 单调队列优化dp
/* poj 1821 n*n*m 暴力*/ #include<iostream> #include<cstdio> #include<cstring> #incl ...
- 安装jdk后出现bash: ./java: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
用sudo yum install glibc.i686命令安装好glibc之后问题就解决了
- 委托、 Lambda表达式和事件——Lambda表达式
/* * 由SharpDevelop创建. * 用户: David Huang * 日期: 2015/7/30 * 时间: 16:32 */ using System; namespace Lambd ...
- 在vSphere5.0虚拟机里的Ubuntu Server 32位安装JDK
本机操作系统Win7 服务器用vSphere 5.0 虚拟机 在虚拟机安装了Ubuntu Server 12.04 1.首先到Oracle官网上下载jdk-7u51-linux-i586.tar.g ...
- VS2015 Cordova Ionic移动开发(三)
一.基础设置 1.修改App名称和程序起始页 打开config.xml配置文件显示如下,在[通用]选项卡中,将显示名称和起始页,修改为自己想要的名称即可. 如需直接在xml文件中修改:右击config ...
- Android平台的四大天王:Activity, Service, ContentProvider, BroadcastReceiver
今天开始要自学android,刚看到百度知道上面这段话,觉得不错(不过已经是2011年8月的回答了): Android系统的手机的每一个你能看到的画面都是一个activity,它像是一个画布,随你在上 ...
- 简单的SqlHelper
namespace Login { class SqlHelper { //连接数据库的字符串 //static string dataConnection = "server=***-PC ...
- 在xcode6.1和ios10.10.1环境下实现app发布
之前写过在xcode6.1和ios10.10.1环境下实现真机测试,以及最近提交的app一直在审核当中,所以木有发布如何实现app发布来分享给大家.刚好昨天app审核通过了,所以就分享一篇如何实现ap ...
- >=ios8 应用内跳转到系统设置界面-openURL
iOS8以后,苹果允许从应用内跳转到系统设置,但是调试结果表明,跳不到具体的设置项,使用前应该判断当前是否能够跳转到系统设置. 代码: NSURL *url = [NSURL URLWithStrin ...