hdu5336 Walk Out
题意是:入口:地图的左上角,出口,地图的右上角,求所经过的路径的二进制数最小
照着题解敲了一遍
思路是:首先 二进制 的 位数 越小 越好,其次 二进制的前缀零越多 表示 值越小
首先 在前缀是0的情况下走到最远(最远的定义是 当前坐标是 i , j 则 在保证 位数越小的情况下 则 还剩下 n-i + m-j 的路要走)
剩下的路 必须 向 右走 或者向 下 走,然后 在 其中 选取 0 尽量 多的 路
代码:非原创!!!(from 多校题解)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue> using namespace std;
const int MAXN = +;
bool vis[MAXN][MAXN];
char graph[MAXN][MAXN];
int n,m;
int dr[] = {,,,-};
int dc[] = {,-,,};
struct Node{
int x,y;
}; void bfs(){
memset(vis,,sizeof(vis));
vis[][] = ;
queue<Node>q;
Node tmp;
tmp.x = ,tmp.y = ;
q.push(tmp);
int mx = ;
while(!q.empty()){
tmp = q.front();
q.pop();
if(graph[tmp.x][tmp.y] > ''){
continue;
}
for(int i = ;i < ;i++){
int xx = tmp.x + dr[i];
int yy = tmp.y + dc[i];
if(xx<||yy<||xx>n||yy>m || vis[xx][yy]){
continue;
}
// cout << "x = " << tmp.x << " y = " << tmp.y << endl;
Node tt;
tt.x = xx;
tt.y = yy;
vis[xx][yy] = ;
mx = max(mx,xx+yy);
// cout << "x = " << xx << " y = " << yy << endl << endl;;
q.push(tt);
}
}
if(vis[n][m] && graph[n][m] == ''){
printf("0\n");
return;
}
printf("");
for(int i = mx;i < m+n;i++){
char mi = '';
for(int j = ;j <= n;j++){
if(i-j > && i-j <= m && vis[j][i-j]){
mi = min(mi,graph[j+][i-j]); //向右走
mi = min(mi,graph[j][i-j+]);//向下走
}
}
printf("%c",mi);
for(int j = ;j <= n;j++){
if(i-j > && i-j <= m && vis[j][i-j]){
if(mi == graph[j+][i-j]){
vis[j+][i-j] = ;
}
if(mi == graph[j][i-j+]){
vis[j][i-j+] = ;
}
}
}
}
printf("\n");
}
int main(){
// freopen("input.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i = ;i <= n;i++){
scanf("%s",graph[i]+);
}
for(int i = ;i <= n+;i++){
graph[i][] = '';
graph[i][m+] = '';
}
for(int i = ;i < m+;i++){
graph[][i] = '';
graph[n+][i] = '';
}
bfs();
}
return ;
}
hdu5336 Walk Out的更多相关文章
- python os.walk()
os.walk()返回三个参数:os.walk(dirpath,dirnames,filenames) for dirpath,dirnames,filenames in os.walk(): 返回d ...
- LYDSY模拟赛day1 Walk
/* 依旧考虑新增 2^20 个点. i 只需要向 i 去掉某一位的 1 的点连边. 这样一来图的边数就被压缩到了 20 · 2^20 + 2n + m,然后 BFS 求出 1 到每个点的最短路即可. ...
- How Google TestsSoftware - Crawl, walk, run.
One of the key ways Google achievesgood results with fewer testers than many companies is that we ra ...
- poj[3093]Margaritas On River Walk
Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...
- os.walk()
os.walk() 方法用于通过在目录树种游走输出在目录中的文件名,向上或者向下. walk()方法语法格式如下: os.walk(top[, topdown=True[, onerror=None[ ...
- 精品素材:WALK & RIDE 单页网站模板下载
今天,很高兴能向大家分享一个响应式的,简约风格的 HTML5 单页网站模板.Walk & Ride 这款单页网站模板是现代风格的网页模板,简洁干净,像素完美,特别适合用于推广移动 APP 应用 ...
- 股票投资组合-前进优化方法(Walk forward optimization)
code{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && docu ...
- Go Walk教程 - 流程控制( switch)
Go的 switch 非常灵活,表达式不必是常量或整数,执行的过程从上至下,直到找到匹配项,不要break: var score =98 var result string switch score/ ...
- [py]os.walk爬目录&sys.argv灵活获取参数
1, 遍历目录 os.walk('/tmp') os.next() 2,sys.argv ######################################## py@lanny:~/t ...
随机推荐
- javascript模块加载框架seajs详解
SeaJS是一个遵循commonJS规范的javascript模块加载框架,可以实现javascript的模块化开发和模块化加载(模块可按需加载或全部加载).SeaJS可以和jQuery完美集成,使用 ...
- 资源文件(.RES)的应用
资源档有什麽用处呢?最重要的有两个地方1.国际发行:我们将Application中所有的文字从Resource用读取,那麽,只要更动 Resource档的内容,就可以用不同语言的 ...
- zkw好写吗
codeforces果然名不虚传,仔细研读了该篇文章后感觉受益良多! 其实这篇文章探讨的就是zkw,其中的一些写法让我大开眼界,感觉是zkw那篇论文的又一个提升: 内存不再是2的幂了,直接就是\(2n ...
- Zoj 3842 Beauty of Array
Problem地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5520 根据题目的要求,需要算出所有连续子数组的the be ...
- 【Web】throw和throws的区别和用法。
1.throws关键字通常被应用在声明方法时,用来指定可能抛出的异常.多个异常可以使用逗号隔开.当在主函数中调用该方法时,如果发生异常,就会将异常抛给指定异常对象.如下面例子所示: public cl ...
- 史上最详细的Android Studio系列教程一--下载和安装
链接地址:http://segmentfault.com/a/1190000002401964#articleHeader4 原文链接:http://stormzhang.com/devtools/2 ...
- nodejs--express开发个人博客(-)
写完了入门笔记,开始进入开发阶段吧.基于上一节的内容,现在着手开发个人博客系统.先划分一下功能吧 /:首页 /login:登陆 /reg:注册 /post:发表文章 /logout:退出 首先规划一下 ...
- 【四】注入框架RoboGuice使用:(Your First System Service Injection)
上一篇我们简单的介绍了一下RoboGuice的使用([三]注入框架RoboGuice使用:(Your First Resource Injection)),今天我们来看下系统服务的使用注解的方法: 为 ...
- Android平台调用Web Service:演示样例
近期在学习Android,随着移动设备的流行,当软件走上商业化的道路,为了争夺市场,肯定须要支持Android的,所以開始接触了Android,只是仅仅了解皮毛就好,由于我们要做管理者嘛,懂点Andr ...
- Wakelock API详解
官方资料 http://developer.android.com/intl/zh-CN/reference/android/os/PowerManager.WakeLock.html http:/ ...