您当前的位置: 百科371电脑/网络C/C++ → 电脑/网络内容 退出登录 用户管理 用户注册
本类热门文章
相关文章
中原建材网
棘手的编程问题

减小字体 增大字体

问题:Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE stdin/stdout 3s 8192K 702 148 Standard Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us. There is a large number of magnetic plates on every door. Every plate has one word written on it. The plates must be arranged into a sequence in such a way that every word begins with the same letter as the previous word ends. For example, the word ``acm can be followed by the word ``motorola. Your task is to write a computer program that will read the list of words and determine whether it is possible to arrange all of the plates in a sequence (according to the given rule) and consequently to open the door. Input SpecificationThe input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer number Nthat indicates the number of plates (1 <= N <= 100000). Then exactly Nlines follow, each containing a single word. Each word contains at least two and at most 1000 lowercase characters, that means only letters a through z will appear in the word. The same word may appear several times in the list. Output SpecificationYour program has to determine whether it is possible to arrange all the plates in a sequence such that the first letter of each word is equal to the last letter of the previous word. All the plates from the list must be used, each exactly once. The words mentioned several times must be used that number of times. If there exists such an ordering of plates, your program should print the sentence Ordering is possible.. Otherwise, output the sentence The door cannot be opened.. Sample Input32acmibm3acmmalformmouse2okokSample OutputThe door cannot be opened.Ordering is possible.The door cannot be opened.  

比较普通的acm题目而已(貌似是IOI?) 没有二楼说的那么玄, 还密码学呢..

说下算法, 如果楼主要求, 可以给代码

1. 每个单词起作用的也就是头尾两个字母, 很好理解

2. 如果某个单词集合满足题目条件, 则可以推出单词集合具有以下性质:设所有单词首字母构成集合A, 尾字母构成集合B, 容易想到, AB字符数一样, 且最多有一个字符不同, (即仅允许第一个单词的首字母和最后一个单词的尾字母不同)

3. 而同时, 所有满足2性质的单词集合, 都可以满足题中条件(串连起来), 也就是说2是充要条件 (这个有些不好想, 自己在纸上画画)

因此, 只要判断单词集合是否满足性质2即可, 而这个是很简单的事情

如果你对Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE stdin/stdout 3s 8192K 702 148 Standard Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us. There is a large number of magnetic plates on every door. Every plate has one word written on it. The plates must be arranged into a sequence in such a way that every word begins with the same letter as the previous word ends. For example, the word ``acm can be followed by the word ``motorola. Your task is to write a computer program that will read the list of words and determine whether it is possible to arrange all of the plates in a sequence (according to the given rule) and consequently to open the door. Input SpecificationThe input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer number Nthat indicates the number of plates (1 <= N <= 100000). Then exactly Nlines follow, each containing a single word. Each word contains at least two and at most 1000 lowercase characters, that means only letters a through z will appear in the word. The same word may appear several times in the list. Output SpecificationYour program has to determine whether it is possible to arrange all the plates in a sequence such that the first letter of each word is equal to the last letter of the previous word. All the plates from the list must be used, each exactly once. The words mentioned several times must be used that number of times. If there exists such an ordering of plates, your program should print the sentence Ordering is possible.. Otherwise, output the sentence The door cannot be opened.. Sample Input32acmibm3acmmalformmouse2okokSample OutputThe door cannot be opened.Ordering is possible.The door cannot be opened.这个问题有好的意见或 建议,请留言
[] [返回上一页] [打 印]
电脑/网络评论 (评论内容只代表网友观点,与本站立场无关!)

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码

中原建材网 简单版 站长QQ:382546553