记录一个菜逼的成长。。

DESCRIPTION

Boggle is a word game designed by Allan Turoff and distributed by Hasbro. It involves a board made up of 16 cubic dice, where each die has a letter printed on each of its sides. At the beginning of the game, the 16 dice are shaken and randomly distributed into a 4-by-4 tray, with only the top sides of the dice visible. The players compete to accumulate points by building valid words out of the dice according to the following rules:

A valid word must be composed by following a sequence of adjacent dice—two dice are adjacent if they are horizontal, vertical, or diagonal neighbors.A valid word can use each dice at most once.A valid word must contain at least 3 letters.A valid word must be in the dictionary (which typically does not contain proper nouns).
Words are scored according to their length, using this table:
| Word length | points |
| :---------: | :----: |
|     0-2     |   0    |
|     3-4     |   1    |
|      5      |   2    |
|      6      |   3    |
|      7      |   5    |
|     8-9     |   11   |
To simplify the problem, now we will play this game on a 3-by-3 board. And the rule 4 will be ignored. Now you will be given n words record which are given by players. You need to check the score of these words. If the word is not valid according to rules mentioned above except the rule 4, the score of it is zero.

INPUT
The first line of input contains an integer T(T<=5) indicating the number of test cases.
For each test case, the first three lines, each line contains three uppercase English letters. The next line contains a integer n(1 <= n <= 50000), indicating the number of words. The following n lines, each line contains a word(word’s length <= 9). The word only consist uppercase English letters.
OUTPUT
For each case, output “Case #X:” in a line where X is the case number, staring from 1. Then for each word, output the score in a line.
SAMPLE INPUT
1
ABC
DEF
GHI
4
ADG
AFI
A
ABCFI
SAMPLE OUTPUT
Case #1:
1
0
0
2
SOLUTION
“玲珑杯”ACM比赛 Round #8

题目链接
题目大意:
给你3*3的字符矩阵,q次询问,每次询问给你一个单词,如果满足条件输出这个单词的分数,不满足则输出0。
1.单词组成有八个方向
2.每个格子的字母只能用一次
3.不能少于3个字母

直接暴力搜索即可。。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define cl(a,b) memset(a,b,sizeof(a))
char g[5][5],str[20];
bool vis[5][5];
int score[] = {0,0,0,1,1,2,3,5,11,11};
int dx[] = {-1,-1,0,1,1,1,0,-1},dy[] = {0,1,1,1,0,-1,-1,-1};
bool dfs(int x,int y,int pos,int n)
{if(pos == n)return true;for( int i = 0; i < 8; i++ ){int nx = x + dx[i],ny = y + dy[i];if(nx < 0 || nx >= 3 || ny < 0 || ny >= 3)continue;if(vis[nx][ny] || g[nx][ny] != str[pos])continue;vis[nx][ny] = 1;bool ret = dfs(nx,ny,pos+1,n);vis[nx][ny] = 0;if(ret)return true;}return false;
}
int main()
{int T,cas = 1;scanf("%d",&T);while(T--){for( int i = 0; i < 3; i++ )scanf("%s",g[i]);int q;scanf("%d",&q);printf("Case #%d:\n",cas++);while(q--){scanf("%s",str);cl(vis,0);int len = strlen(str);if(len > 9 || len < 3){printf("0\n");continue;}bool ret  = false;for( int i = 0; i < 3; i++ ){ret = false;for( int j = 0; j < 3; j++ ){if(g[i][j] == str[0]){vis[i][j] = 1;ret = dfs(i,j,1,len);if(ret)break;vis[i][j] = 0;}}if(ret)break;}if(ret)printf("%d\n",score[len]);else puts("0");}}return 0;
}

玲珑杯”ACM比赛 Round #8-D XJT Loves Boggle(dfs)相关推荐

  1. “玲珑杯”ACM比赛 Round #21-C-战舰萝莉(线段树区间更新)

    "玲珑杯"ACM比赛 Round #21 Start Time:2017-09-23 17:00:00 End Time:2017-09-23 19:30:00 Refresh T ...

  2. “玲珑杯”ACM比赛 Round #18 C -- 图论你先敲完模板【Dp】

    C -- 图论你先敲完模板 Time Limit:5s Memory Limit:256MByte Submissions:660Solved:160 DESCRIPTION 今天HHHH在操场上跑步 ...

  3. “玲珑杯”ACM比赛 Round #18 ABC题解

    A -- 计算几何你瞎暴力 Time Limit:5s Memory Limit:256MByte Submissions:1597Solved:301 DESCRIPTION 今天HHHH考完了期末 ...

  4. 玲珑杯”ACM比赛 Round #15 D 咸鱼商店【二分+01背包】

    题目链接:http://www.ifrog.cc/acm/problem/1125 题目大意:中文题目,题意请仔细看题面. 解题思路:二分+01背包     01背包的最终结果与其中的顺序无关,我们要 ...

  5. lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP

    E -- Expected value of the expression DESCRIPTION You are given an expression: A0O1A1O2A2⋯OnAnA0O1A1 ...

  6. “玲珑杯”ACM比赛 Round #22 E【贪心】

    题目: http://www.ifrog.cc/acm/problem/1171?contest=1024&no=4 题意: 输入一个字符串,将他重新排列,使得重排之后的字符串的最小表示法,最 ...

  7. “玲珑杯”ACM比赛 Round #24: C. この戦いが終わったら(BFS+bitset优化暴力)

    C -- この戦いが終わったら 给你一个无向图,每次查询的时候给一堆二元组(xi,yi) 求图中有多少个点u与至少一个这次询问给出的二元组(xi,yi)满足dist(u,xi)<=yi,dist ...

  8. “玲珑杯”ACM比赛 Round #19

    A -- A simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 DESCRIPTIO ...

  9. “玲珑杯”ACM比赛 Round #4

    运气不错有个抱枕. 1046 - chess play 题意: 一个n*m的数组,初始全部是'.',然后3种操作,把一个位置变成'w',或者把一个位置变成'r',或者交换两行. 思路: vector的 ...

最新文章

  1. Codeforces Round #359 (Div. 2) C. Robbers' watch 暴力枚举
  2. 微服务架构下的安全认证与鉴权
  3. Eclipse 安装Gradle插件
  4. ArcGis中空间连接join
  5. 踩坑记录:请求接口status返回0
  6. NotificationManager: notifyAsUser: tag=null, id=6, user=UserHandle{0}
  7. [转载] 为什么this()和super()必须是构造函数中的第一条语句?
  8. 国开大学计算机实操,国开大学计算机实操答案一.doc
  9. ​LeetCode刷题实战510:二叉搜索树中的中序后继 II
  10. python小学口算题库生成器_PrimarySchoolMathematics
  11. windows 7计算机用户名和密码忘了,w7笔记本忘记开机密码怎么办_win7笔记本电脑忘记登录密码解决方法-系统城...
  12. Dynamics AX 2009 Trainning
  13. Aqara? 华为?智汀?要真的实现万物互联了吗?
  14. html怎么在文字中加小方框,css之列表数据前加上小方框
  15. java使用多态打印个人信息_java 多态 回顾
  16. linux自动关机取消命令,Linux中Shutdown命令实现定时自动关机
  17. python 爬陌生人qq空间_Python爬取qq空间说说
  18. 文学阅读---菜根谭(1)
  19. 中国全自动洗地机器行业现状调研及趋势分析报告
  20. 添加传奇GM管理员-自定义游戏命令教程

热门文章

  1. 我遇到了bug,请问该如何解决
  2. 安利一个超好用的录屏工具,收藏必备! - 网课、游戏、录音等免费录制
  3. Unity颜色转换(HtmlString和Color)
  4. 网络直播电视之寻找直播地址(下)
  5. php企业后台管理系统模板,企业版PHP后台管理模板【清爽型】修改版~
  6. 哪位仁兄在狂顶精华贴?
  7. Odoo 16 企业版手册 - 库存管理之产品类别
  8. WPS文件转Excel文件怎么转?建议看看这些方法
  9. 名帖121 文徵明 小楷《琴赋》
  10. linux命令下jq的用法(curl 格式化输出json 字符串)