传送门:

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的更多相关文章

  1. Trie树 + DFS - CSU 1457 Boggle

    Boggle Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1457 Mean: 给定n个串,有m个询问. 每个询问 ...

  2. GCPC 2013_A Boggle DFS+字典树 CSU 1457

    上周比赛的题目,由于那个B题被神编译器的优化功能给卡了,就没动过这个题,其实就是个字典树嘛.当然,由于要在Boggle矩阵里得到初始序列,我还一度有点虚,不知道是用BFS还是DFS,最后发现DFS要好 ...

  3. Programming Assignment 4: Boggle

    编程作业四 作业链接:Boggle & Checklist 我的代码:BoggleSolver.java 问题简介 Boggle 是一个文字游戏,有 16 个每面都有字母的骰子,开始随机将它们 ...

  4. 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 ...

  5. UVa - 11283 - PLAYING BOGGLE

    先上题目 Problem F PLAYING BOGGLE Boggle® is a classic word game played on a 4 by 4 grid of letters. The ...

  6. 《算法问题实战策略》 BOGGLE

    oj地址是韩国网站 连接比较慢 https://algospot.com/judge/problem/read/BOGGLE大意如下 输入输出 输入 URLPM XPRET GIAET XTNZY X ...

  7. BZOJ 3083: 遥远的国度 [树链剖分 DFS序 LCA]

    3083: 遥远的国度 Time Limit: 10 Sec  Memory Limit: 1280 MBSubmit: 3127  Solved: 795[Submit][Status][Discu ...

  8. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  9. BZOJ 4196: [Noi2015]软件包管理器 [树链剖分 DFS序]

    4196: [Noi2015]软件包管理器 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1352  Solved: 780[Submit][Stat ...

随机推荐

  1. How To Create A Local Repository For SUSE Linux

    原文地址:http://candon123.blog.51cto.com/704299/1009294/ As you know,you can use the yum command to inst ...

  2. iOS7中的多任务 - Background Fetch,Silent Remote Notifications,Background Transfer Service

    转自:http://onevcat.com/2013/08/ios7-background-multitask/ 在IOS 7 出来不就,公司内部也组织了一次关于IOS 7 特性的的分享,今天看见on ...

  3. 【python】python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte sequence

    python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte ...

  4. python三大web框架Django,Flask,Flask,Python几种主流框架,13个Python web框架比较,2018年Python web五大主流框架

    Python几种主流框架 从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python We ...

  5. PHP检测及判断手机登录用户是安卓或爱疯(iPhone)客户端

    <?php /* PHP 自动判断客户端平台(PC.安卓.iPhone.平板) * strtolower() 函数把字符串转换为小写: * strpos() 函数返回字符串在另一个字符串中第一次 ...

  6. SVG.js Mask覆盖和ClipPath裁剪

    一.SVG.Mask 覆盖物设置 1. var draw = SVG('svg1').size(300, 300); //SVG.Mask 覆盖物设置 var ellipse = draw.ellip ...

  7. protobuf语法简介2

    protobuf语法简介2 1.optional的字段和默认值 如上所述,消息描述中的一个元素可以被标记为"可选的"(optional).一个格式良好的消息可以包含0个或一个opt ...

  8. Java_Freemarker

    ylbtech-Miscellaneos:Java_Freemarker FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页.电子邮件.配置文件.源 ...

  9. Oracle选择性系统授权

    Selective System Grants 问题: 我只想授予XX用户alter system set user_dump_dest 权限! I want to give users the ab ...

  10. asp.net 读取word 文档的方法

    资料一:适合读取并显示(简单而明了) 第一种方法:    Response.ClearContent(); Response.ClearHeaders();   Response.ContentTyp ...