Cross Words
来源:互联网 发布:zookeeper源码 编辑:程序博客网 时间:2024/05/18 00:40
Cross Words
Time Limit:10000MS Memory Limit:65536K
Total Submit:8 Accepted:5
Description
Cross words is such a famous game that we may meet at any corner. Many people dive into the game, including Leilei. But, as everyone knows, Leilei is poor in English, especially in his small size of vocabulary. And soon he finds that some puzzle is so hard to solve because he don’t know some of the key words to be filled in. So now when he gets the solution of one puzzle, he only wonders if the words are out of his knowledge. And as he is too lazy, he leaves the work to you.
A solution of the game is a matrix of R*C characters from the set {‘A’-‘Z’,’*’}.
A word of the game is the consecutive captain letters of one row or one column. The word should be read from top to bottom or from left to right. The word should be “longest”, that means, there should be no more captain letters to the two ends of the word.
For example, here is one puzzle.
*IS**
**CAN
**A**
**N**
The words from the rows are:
IS
CAN
A
N
The words from the column are:
I
SCAN
A
N
So if Leilei don’t know any of the eight words above, he can’t solve the puzzle forever.
Input
At the beginning of the input file, there is the vocabulary of Leilei.
The first line consists of one integer N (0<= N < 16384), which is the size of the vocabulary.
Each of the following N lines consists of one English word. This word is only made up with captain letters ‘A’-‘Z’. No word will be longer than 100 characters.
Then follow multiple test cases.
The first line of each test case there is two positive integers R and C. 0In the following R lines, each consists of C characters, from the set {‘A’-‘Z’,’*’}.
A line with R=C=0 indicating the end of the input file.
Output
For each test case, output one line consists of one word “YES” if Leilei can solve the puzzle or “NO” if not.
Sample Input
6ISCANISCANAN4 5*IS****CAN**A****N**4 5*IS****CAN**AN***N**0 0
Sample Output
YESNO
Hint
*THIS*IS*ONE*LINE*WITH*SEVEN*WORDS*
选自:第二届ACM/ICPC珠海区域赛
思路:本题只是一道二分查找(二叉查找)的题,我这里处理这个单词矩阵方法有点繁琐!有好方法的留下言吧!
#include<iostream>
using namespace std;
struct node
{
char a[110];
}nod[16390];
int cmp(const void *c,const void *b)
{
return strcmp( ((node*)c)->a,((node*)b)->a );
}
char a[120][120];
char text[120];
int main()
{
int N,i,j,R,C,temp,temp1,jump1,yes,jump2;
scanf("%d",&N);
for(i=0;i<N;i++)
{
scanf("%s",nod[i].a);
}
qsort(nod,N,sizeof(nod[0]),cmp);
while(scanf("%d%d",&R,&C)!=EOF)
{
if(R==0&&C==0)
break;
yes=-1;
for(i=0;i<R;i++)
{
getchar();
for(j=0;j<C;j++)
{
scanf("%c",&a[i][j]);
}
}
i=0;
j=0;
for(i;i<R;i++)
{
j=0;
for(j;j<C;j++)
{
temp=0;
if(a[i][j]!='*')
{
yes=0;
text[temp++]=a[i][j];
j++;
while(a[i][j]!='*'&&j<C)
{
text[temp++]=a[i][j];
j++;
}
text[temp]='/0';
if(bsearch(text,nod,N,sizeof(nod[0]),cmp)==NULL)
{
yes=1;
goto jump1;
}
j--;
}
}
}
jump1:;
if(yes==0||yes==-1)
{
i=0;
j=0;
for(i;i<C;i++)
{
j=0;
for(j;j<R;j++)
{
temp=0;
if(a[j][i]!='*')
{
yes=0;
text[temp++]=a[j][i];
j++;
while(a[j][i]!='*'&&j<R)
{
text[temp++]=a[j][i];
j++;
}
text[temp]='/0';
if(bsearch(text,nod,N,sizeof(nod[0]),cmp)==NULL)
{
yes=1;
goto jump2;
}
j--;
}
}
}
jump2:;
}
if(yes==0)
printf("YES/n");
else
printf("NO/n");
}
return 0;
}
- Cross Words
- cross
- words
- words
- Words
- words
- Words
- words
- words
- words
- Words
- words
- The Cross
- Cross Game
- cross join
- CROSS JOIN
- Cross compiler
- Cross Validation
- Huffman编码
- 十字链表
- 切实反思“形式化方法”-David Lorge Parnas
- 编程新手编写代码注意事项
- 如何在vi 中设置tab键为4,显示行号
- Cross Words
- policy-based design
- 模式设计——单例
- 爱你
- 解决添加/删除组件中找不到IIS选项或不能安装的问题
- 对你来说,我只不过是一个过路人,从你的身边一闪而逝,没留下丝丝痕迹……
- 还是算命 -- 这样大规模的算命, 也算比较专业了
- 资源分兑换
- qt线程类---QThread