先上题目

Problem F

PLAYING BOGGLE

Boggle® is a classic word game played on a 4 by 4 grid of letters. The letter grid is randomly generated by shaking 16 cubes labeled with a distribution of letters similar to that found in English words. Players try to find words hidden within the grid.

Words are formed from letters that adjoin horizontally, vertically, or diagonally. However, no letter may be used more than once within a single word.

An example Boggle® letter grid, showing the formation of the words "taxes" and "rise".

The score awarded for a word depends on its length, with longer words being worth more points. Exact point values are shown in the table below. A word is only ever scored once, even if it appears multiple times in the grid.

No. of letters: 3 4 5 6 7 8 or more
Points: 1 1 2 3 5 11

In this problem, your task is to write a program that plays Boggle®.
Given a letter grid and a dictionary of words, you are to calculate the
total score of all the words in the dictionary that can be found in the
grid.

Input

The first line of the input file contains a number N, the number of Boggle® games that follow.

Each Boggle® game begins with 16 capital letters arranged in a 4 by 4 grid,
representing the board configuration for that game.
A blank line always precedes the letter grid.
Following the letter grid is a single number M (1 ≤ M ≤ 100), the number of words in your dictionary
for that game. The next M lines contain the dictionary words, one per line, in no particular order.
Each word consists of between 3 and 16 capital letters.
No single word will appear in the dictionary more than once for a given Boggle® game.

Output

For each Boggle® game in the input, your program should output the total score for that game.
Follow the format given in the sample output.

Sample Input

  1. 2
  2.  
  3. TNXO
  4. AAEI
  5. IOSR
  6. BFRH
  7. 8
  8. TAXES
  9. RISE
  10. ANNEX
  11. BOAT
  12. OATS
  13. FROSH
  14. HAT
  15. TRASH
  16.  
  17. FNEI
  18. OBCN
  19. EERI
  20. VSIR
  21. 1
  22. BEER

Output for the Sample Input

  1. Score for Boggle game #1: 6
  2. Score for Boggle game #2: 1
  3.  
  4.   排位赛时这一题没有做出来,因为题意理解错了= =,以为是找到一个单词以后,这个单词用过的格子全部都不可以再用了,但其实不是这样。这一题的题意是不同长度的单词有不同的得分,给出字符矩阵让你在其中找一系列单词,找到一个单词就得到特定的分数,同一个单词得分只计算
    一次,当然,也有可能里面找不到给出的单词,如果是这样就加0分,最后问你可以得到多少得分。由于这一题给的矩阵是4*4,完全就是一个裸的dfs,只需跑一边dfs就出结果。
  5.  
  6. 上代码:
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <map>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. map<string,int> M;
  9. char s[][],c[];
  10. bool mark[][];
  11.  
  12. bool dfs(int i,int j,int n)
  13. {
  14. if(i< || j<) return ;
  15. if(mark[i][j]) return ;
  16. if(s[i][j]==c[n])
  17. {
  18. if(c[n+]=='\0') return ;
  19. mark[i][j]=;
  20. if(dfs(i-,j-,n+)) return ; if(dfs(i-,j,n+)) return ; if(dfs(i-,j+,n+)) return ;
  21. if(dfs(i,j-,n+)) return ; if(dfs(i,j+,n+)) return ;
  22. if(dfs(i+,j-,n+)) return ; if(dfs(i+,j,n+)) return ; if(dfs(i+,j+,n+)) return ;
  23. mark[i][j]=;
  24. }
  25. return ;
  26.  
  27. }
  28.  
  29. bool check()
  30. {
  31. int i,j;
  32. for(i=;i<;i++)
  33. {
  34. for(j=;j<;j++)
  35. {
  36. if(s[i][j]==c[])
  37. {
  38. memset(mark,,sizeof(mark));
  39. if(dfs(i,j,)) return ;
  40. }
  41. }
  42. }
  43. return ;
  44. }
  45.  
  46. int main()
  47. {
  48. int m,t,i,j,maxn,da,k;
  49. //freopen("data.txt","r",stdin);
  50. scanf("%d",&t);
  51. for(k=;k<=t;k++)
  52. {
  53. M.clear();
  54. memset(s,,sizeof(s));
  55. for(i=;i<;i++)
  56. {
  57. scanf("%s",s[i]);
  58. }
  59. scanf("%d",&m);
  60. maxn=;
  61. for(j=;j<m;j++)
  62. {
  63. scanf("%s",c);
  64. if(M.count(c)>) continue;
  65. M[c]=;
  66. if(!check()) continue;
  67. da=strlen(c);
  68. if(da<) continue;
  69. switch(da)
  70. {
  71. case :
  72. case : da=;break;
  73. case : da=;break;
  74. case : da=;break;
  75. case : da=;break;
  76. default :da=;
  77. }
  78. maxn=da+maxn;
  79. }
  80. printf("Score for Boggle game #%d: %d\n",k,maxn);
  81. }
  82. return ;
  83. }

11283

  1.  

UVa - 11283 - PLAYING BOGGLE的更多相关文章

  1. UVA 1482 - Playing With Stones(SG打表规律)

    UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函 ...

  2. [uva] 10067 - Playing with Wheels

    10067 - Playing with Wheels 题目页:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Ite ...

  3. uva 1482 - Playing With Stones

    对于组合游戏的题: 首先把问题建模成NIM等经典的组合游戏模型: 然后打表找出,或者推出SG函数值: 最后再利用SG定理判断是否必胜必败状态: #include<cstdio> #defi ...

  4. uva 6757 Cup of Cowards(中途相遇法,貌似)

    uva 6757 Cup of CowardsCup of Cowards (CoC) is a role playing game that has 5 different characters (M ...

  5. 09_Sum游戏(UVa 10891 Game of Sum)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P67 例题28: 问题描述:有一个长度为n的整数序列,两个游戏者A和B轮流取数,A先取,每次可以从左端或者右端取一个或多个数,但不能两端 ...

  6. UVA 1292 十二 Strategic game

    Strategic game Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Sta ...

  7. 【UVa 10881】Piotr's Ants

    Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...

  8. 容斥原理--计算错排的方案数 UVA 10497

    错排问题是一种特殊的排列问题. 模型:把n个元素依次标上1,2,3.......n,求每一个元素都不在自己位置的排列数. 运用容斥原理,我们有两种解决方法: 1. 总的排列方法有A(n,n),即n!, ...

  9. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

随机推荐

  1. bzoj 2005 & 洛谷 P1447 [ Noi 2010 ] 能量采集 —— 容斥 / 莫比乌斯反演

    题目:bzoj 2005 https://www.lydsy.com/JudgeOnline/problem.php?id=2005   洛谷 P1447 https://www.luogu.org/ ...

  2. javascript 将变量值作为对象属性 获取对象对应的值

    例子 var var="name"; var objname="obj"; objname=objname+"."+var; alert(e ...

  3. category中添加属性的简单方式

    一.概念扩充: 1.如我们所知,使用category是用来对现有类进行功能扩展,或者将类分成多模块的一种方式.由声明和实现两部分组成.可以单独写成Objiective-C File类型文件(包含.h和 ...

  4. Java 最基础的三种排序排序

    主要讲五个排序,冒泡排序.选择排序.插入排序 1)冒泡排序 /** * 冒泡排序 (默认升序排) * 相邻两个相比较,较大的向后放,从数组或者集合中的第一个与第二个比较到倒数第二个与最后一个比较为一轮 ...

  5. cocos2d-x https

    cocos2d-x :2.1.3HttpClient.cpp文件中  bool configureCURL(CURL *handle)后边添加如下两句: curl_easy_setopt(handle ...

  6. OneThink管理平台 ,登录后台一直提示验证码错误

    可能是数据库的错.上传到服务器以后要改2个地方的配置,\Application\Common\Conf\config.php(整站公用配置文 件),\Application\User\Conf\con ...

  7. 单个句子<code> 多行代码显示<pre> 键盘输入<kbd>

    1.用来显示单个句子或者单个单词:<code>……</code> 2.用来显示多行代码:<pre>……</pre> 当行数高度大于340px,自动出现y ...

  8. var _this = this 是干什么的

    因为JS可以多层嵌套代码可能下面还可以再嵌一个方法引用this就会变成子方法控制的对象如果需要上级的对象在没有参数的情况下前面前提做了一个临时变量_this可以保存上级对象子方法中就可以用_this来 ...

  9. windows和linux无法访问VMware中linux的tomcat主页问题

    1.一定确定自己的tomcat服务器是启动的.(为了确保保险可以在测试前重新shutdown,startup一次) 2.确定自己访问的ip地址和端口号是正确的 如果是VMware外部windows的话 ...

  10. Arduino 红外接收

    一.实物图 二.例子代码 注:git clone https://github.com/z3t0/Arduino-IRremote.git 放到Arduino 的libraries目录下面  从遥控器 ...