DFS csu1719 Boggle
传送门: id=1719">点击打开链接
题意:真正的题意是,告诉你一些字符串。然后告诉你非常多个字符格子,问这些字符串是否能在字符格子中连起来,在格子中对角线也觉得是连在一起的。假设格子中的字符是q,事实上是代表着qu
思路:这题迷之英语。各种猜题意啊,,只是运气好比較早就猜中了。嘿嘿嘿
懂题意了后就非常easy了,DFS各种搜即可了,由于数据范围比較小
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#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<int, int> 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;
}
DFS csu1719 Boggle的更多相关文章
- Trie树 + DFS - CSU 1457 Boggle
Boggle Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1457 Mean: 给定n个串,有m个询问. 每个询问 ...
- GCPC 2013_A Boggle DFS+字典树 CSU 1457
上周比赛的题目,由于那个B题被神编译器的优化功能给卡了,就没动过这个题,其实就是个字典树嘛.当然,由于要在Boggle矩阵里得到初始序列,我还一度有点虚,不知道是用BFS还是DFS,最后发现DFS要好 ...
- Programming Assignment 4: Boggle
编程作业四 作业链接:Boggle & Checklist 我的代码:BoggleSolver.java 问题简介 Boggle 是一个文字游戏,有 16 个每面都有字母的骰子,开始随机将它们 ...
- uvalive 7299 Boggle
Boggle is a game in which 16 dice with letters on each side are placed into a 4 × 4 grid. Players th ...
- UVa - 11283 - PLAYING BOGGLE
先上题目 Problem F PLAYING BOGGLE Boggle® is a classic word game played on a 4 by 4 grid of letters. The ...
- 《算法问题实战策略》 BOGGLE
oj地址是韩国网站 连接比较慢 https://algospot.com/judge/problem/read/BOGGLE大意如下 输入输出 输入 URLPM XPRET GIAET XTNZY X ...
- BZOJ 3083: 遥远的国度 [树链剖分 DFS序 LCA]
3083: 遥远的国度 Time Limit: 10 Sec Memory Limit: 1280 MBSubmit: 3127 Solved: 795[Submit][Status][Discu ...
- BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2221 Solved: 1179[Submit][Sta ...
- BZOJ 4196: [Noi2015]软件包管理器 [树链剖分 DFS序]
4196: [Noi2015]软件包管理器 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1352 Solved: 780[Submit][Stat ...
随机推荐
- [Node.js]操作redis
摘要 在实际开发中,免不了要操作mysql,mongodb,redis等数据存储服务器.这里先简单介绍如何操作redis. 一个例子 关于redis服务端的安装这里不再介绍,重点不在这里.感兴趣的可以 ...
- RxJS 简介:可观察对象、观察者与操作符
RxJS 简介:可观察对象.观察者与操作符 对于响应式编程来说,RxJS 是一个不可思议的工具.今天我们将深入探讨什么是 Observable(可观察对象)和 observer(观察者),然后了解如何 ...
- .NET Out Of Memory Exception - Used 1.3GB but have 16GB installed
I am getting an Out Of Memory exception in my c# application when the memory usage for the applicati ...
- ISO 8601: Delphi way to convert XML date and time to TDateTime and back (via: Stack Overflow)
Recently I needed a way of concerting back and forth ISO 8601 DateTime values used in XML from Delph ...
- Subversion detected an unsupported working copy version
关于这个错误:Subversion detected an unsupported working copy version while checking the status of 'XXXX'. ...
- python测试开发django-20.添加创建时间DateTimeField
前言 我们在admin后台发布一篇文章的时候,一般会有创建时间和最后更新时间这2个字段,创建时间就是第一次编辑文章的时候自动添加的,最后更新时间就是每次修改文章的内容后自动更新 在models.py建 ...
- Build Web Apps in Node and Express视频下载
上传到百度云了,点击这里下载>> 作者使用的是Mac系统,不过Windows也差不多,主要理解express一些基本配置和使用,讲的比较基础,希望对node.js.express有兴 ...
- CTO、CIO
对于不从事技术研发的企业,完全不必要设立CTO这一职位,但是CIO是要始终存在为企业提供更好的咨询服务.有时CT0和CIO是同一个人,毕竟是信息时代嘛!CIO的角色从过去IT时代的交付型,转变为DT时 ...
- HTML5 本地文件操作之FileSystemAPI实例(四)
目录操作Demo二 1.删除目录 window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSyst ...
- 【转】group_concat函数详解
转自: http://hchmsguo.iteye.com/blog/555543 问了好多人,都不知道group_concat这个函数. 这个函数好啊,能将相同的行组合起来,省老事了. MySQL中 ...