DFS csu1719 Boggle
题意:真正的题意是,告诉你一些字符串。然后告诉你非常多个字符格子,问这些字符串是否能在字符格子中连起来,在格子中对角线也觉得是连在一起的。假设格子中的字符是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 ...
随机推荐
- Delphi模拟最小化恢复关闭按纽
https://yq.aliyun.com/wenji/96083 本文讲的是Delphi模拟最小化恢复关闭按纽, 我们做多文档应用程序开发时,如果在主From中指定mainMenu时,在主菜单上右角 ...
- [经使用有效]Sqlserver2005附加数据库时出错提示操作系统错误5(拒绝访问)错误5120的解决办法
sqlserver2005附加数据库时出错提示操作系统错误5(拒绝访问)错误5120的解决办法 最近几天从网上找了几个asp.net的登录案例想要研究研究代码,结果在用 Sql Server2005附 ...
- NSString 和 NSData 转换
NSString 转换成NSData 对象 NSData* xmlData =[@"testdata" dataUsingEncoding:NSUTF8StringEncoding ...
- C#编程(五十三)----------字典Dictionary<TKey,TValue>
字典 关键字:Dicitionary 说明: 必须包含命名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由两个元组组成:键和值). 键必须 ...
- [Web 前端] CSS 盒子模型,绝对定位和相对定位
cp : https://blog.csdn.net/web_yh/article/details/53239372 一.盒子模型: 标准模式和混杂模式(IE).在标准模式下浏览器按照规范呈现页面:在 ...
- TeXLive里面集成了CTeX,Lyx是一个编辑软件
TeXLive里面集成了CTeX,LaTeX是排版引擎,CTeX和TeXLive是发行版.LaTeX是毛坯房,CTeX和TeX Live是带精装的房子.CTeX 套装是一个个人作品,存在很多问题.这些 ...
- Qt中printsupport的注意点和使用方法
问题:Qt中包含QPrintDialog.QPrinter.QPrintPreviewDialog失败:在引入printsupport后报cpp:651: error: undefined refer ...
- 强大的模板引擎开源软件NVelocity
背景知识NVelocity(http://sourceforge.net/projects/nvelocity )是从java编写的Velocity移植的.net版本,是java界超强的模版系统,.n ...
- DatabaseMirroring搭建
1. 概述 数据库镜像维护一个数据库的两个副本,这两个副本必须驻留在不同的 SQL Server 数据库引擎 服务器实例上.通常,这些服务器实例驻留在不同位置的计算机上.启动数据库上的数据库镜像 ...
- 解决MTP device安装失败,手机无法被读取
操作步骤: 1. 我的电脑—>管理—>设备管理器—>便携设备(MTP)-->右击-更新驱动 2. 选择浏览计算机以查找驱动程序软件—>从计算机列表选择—>MTP ...