博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DFS csu1719 Boggle
阅读量:7036 次
发布时间:2019-06-28

本文共 1670 字,大约阅读时间需要 5 分钟。

传送门:

题意:真正的题意是,告诉你一些字符串。然后告诉你非常多个字符格子,问这些字符串是否能在字符格子中连起来,在格子中对角线也觉得是连在一起的。假设格子中的字符是q,事实上是代表着qu

思路:这题迷之英语。各种猜题意啊,,只是运气好比較早就猜中了。嘿嘿嘿

懂题意了后就非常easy了,DFS各种搜即可了,由于数据范围比較小

#include #include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define fuck(x) cout << "[" << x << "]"#define FIN freopen("input.txt", "r", stdin)#define FOUT freopen("output.txt", "w+", stdout)using namespace std;typedef long long LL;typedef pair
PII; const int MX = 200 + 5;string A[MX]; int n, m;char stemp[MX];char S[10][10], vis[10][10]; bool DFS(int id, int i, int x, int y, char w) { int len = A[id].length(); if(A[id][i] != w) return false; if(w == 'q') { if(!(i + 1 < len && A[id][i+1] == 'u')) return false; else i++; } if(i == len - 1) return true; vis[x][y] = 1; for(int dx = -1; dx <= 1; dx++) { for(int dy = -1; dy <= 1; dy++) { if(dx == 0 && dy == 0) continue; int nx = dx + x, ny = dy + y; if(nx < 0 || nx > m || ny < 0 || ny > m || vis[nx][ny]) continue; if(DFS(id, i + 1, nx, ny, S[nx][ny])) { vis[x][y] = 0; return true; } } } vis[x][y] = 0; return false;} int main() { //FIN; while(~scanf("%d", &n)) { for(int i = 1; i <= n; i++) { scanf("%s", stemp); A[i] = string(stemp); } sort(A + 1, A + 1 + n); while(scanf("%d", &m), m) { for(int i = 1; i <= m; i++) { scanf("%s", S[i] + 1); } for(int id = 1; id <= n; id++) { bool sign = false; for(int i = 1; i <= m; i++) { for(int j = 1; j <= m; j++) { if(DFS(id, 0, i, j, S[i][j])) { sign = true; break; } } if(sign) break; } if(sign) printf("%s\n", A[id].c_str()); } printf("-\n"); } } return 0;}

转载地址:http://wbnal.baihongyu.com/

你可能感兴趣的文章
地平线谭洪贺:AI芯片怎么降功耗?从ISSCC2017说起
查看>>
《树莓派用户指南(第3版)》——第1篇 主板 第1章 初识树莓派 1.1 主板简介...
查看>>
MySQL · myrocks · fast data load
查看>>
使用 Linux/Unix 进行文本处理
查看>>
【直播系列之一】1篇文章看懂峰值带宽、流量、转码、连麦、截图五大直播计费方式...
查看>>
PostgreSQL 巧妙的数据采样方法
查看>>
[LeetCode]--232. Implement Queue using Stacks
查看>>
浅谈Android应用保护(一):Android应用逆向的基本方法
查看>>
maven 配置: 修改默认的 .m2仓库 默认存储路径.
查看>>
手机直播连麦技术分析
查看>>
运维之殇
查看>>
System.ServiceModel.CommunicationException: 接收HTTP 响应时发生错误
查看>>
JSP获取spring 的容器ApplicationContext
查看>>
路由器的远程访问
查看>>
PHP 高级编程之多线程(四)-多线程与ZeroMQ
查看>>
Java发送和接收广播的UDP,用于探测局域网中指定类型的设备
查看>>
MySQL 复制过滤详解
查看>>
无法读取此系统上以前注册的服务器的列表。请在“已注册的服务器”窗口中重新注册您的服务器...
查看>>
【COCOS2DX-LUA 脚本开发之九】使用COCOS2DX-LUAPROXY便捷LUA项目快速使用COCOS2DX引擎EXTENSIONS扩展包...
查看>>
【翻译】揭秘:MySQL Pool Scanner(MPS)
查看>>