Play on Words

题目描述

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. 

输入描述:

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

输出描述:

Your 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.". 
       
示例1

输入

3
2
acm
ibm
3
acm
malform
mouse
2
ok
ok

输出

The door cannot be opened.
Ordering is possible.
The door cannot be opened.
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<time.h>
#include<map>
#include<algorithm>
#define ll long long
#define eps 1e-5
#define oo 1000000007
#define pi acos(-1.0)
#define MAXN 100005
#define MAXM 500005
using namespace std; 
int P[2][26],father[26];
bool used[26];
char s[1005];
int getfather(int x)
{
       if (father[x]==x) return x;
       return father[x]=getfather(father[x]);
}
int main()
{       
       int i,cases,n,m,x,y,t1,t2;
       scanf("%d",&cases);
       while (cases--)
       {
               scanf("%d",&n);
               memset(used,false,sizeof(used));
               memset(P,0,sizeof(P));
               for (i=0;i<26;i++) father[i]=i;
               for (i=1;i<=n;i++)
               {
                      scanf("%s",s+1);
                      x=s[1]-'a',y=s[strlen(s+1)]-'a';
                      P[0][x]++,P[1][y]++;
                      father[getfather(x)]=getfather(y);
                      used[x]=used[y]=true;
                      m=getfather(x);
               }
               if (n==1)
               {
                      printf("Ordering is possible.\n");
                      continue;
               }
               for (i=0;i<26;i++)
                  if (used[i] && getfather(i)!=m) break;
               if (i<26)
               {
                      printf("The door cannot be opened.\n");
                      continue;
               }
               t1=t2=0;
               for (i=0;i<26;i++)
               {
                      if (P[0][i]==P[1][i]) continue;
                      if (P[0][i]+1==P[1][i]) t1++;
                      else
                      if (P[1][i]+1==P[0][i]) t2++;
                      else break;
               }
               if (i<26 || !(t1==1 && t2==1 || !t1 && !t2))
                      printf("The door cannot be opened.\n");
                 else
                      printf("Ordering is possible.\n");
       }
       return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
My first encounter with the Java programming language was during a one-week Java training session in 1997. I did not get a chance to use Java in a project until 1999. I read two Java books and took a Java 2 programmer certification examination. I did very well on the test, scoring 95 percent. The three questions that I missed on the test made me realize that the books that I had read did not adequately cover details of all the topics. I made up my mind to write a book on the Java programming language. So, I formulated a plan to cover most of the topics that a Java developer needs to use Java effectively in a project, as well as to become certified. I initially planned to cover all essential topics in Java in 700 to 800 pages. As I progressed, I realized that a book covering most of the Java topics in detail could not be written in 700 to 800 pages. One chapter alone that covered data types, operators, and statements spanned 90 pages. I was then faced with the question, “Should I shorten the content of the book or include all the details that I think a Java developer needs?” I opted for including all the details in the book, rather than shortening its content to maintain the original number of pages. It has never been my intent to make lots of money from this book. I was never in a hurry to finish this book because that rush could have compromised the quality and coverage. In short, I wrote this book to help the Java community understand and use the Java programming language effectively, without having to read many books on the same subject. I wrote this book with the plan that it would be a comprehensive one-stop reference for everyone who wants to learn and grasp the intricacies of the Java programming language. One of my high school teachers used to tell us that if one wanted to understand a building, one must first understand the bricks, steel, and mortar that make up the building. The same logic applies to most of the things that we want to understand in our lives. It certainly applies to an understanding of the Java programming language. If you want to master the Java programming language, you must start by understanding its basic building blocks. I have used this approach throughout this book, endeavoring to build upon each topic by describing the basics first. In the book, you will rarely find a topic described without first learning about its background. Wherever possible, I tried to correlate the programming practices with activities in daily life. Most of the books about the Java programming language available in the market either do not include any pictures at all or have only a few. I believe in the adage, “A picture is worth a thousand words.” To a reader, a picture makes a topic easier to understand and remember. I have included plenty of illustrations in the book to aid readers in understanding and visualizing the concepts. Developers who have little or no programming experience have difficulty in putting things together to make it a complete program. Keeping them in mind, the book contains over 390 complete Java programs that are ready to be compiled and run. I spent countless hours doing research when writing this book. My main sources were the Java Language Specification, whitepapers, and articles on Java topics, and Java Specification Requests (JSRs). I also spent quite a bit of time reading the Java source code to learn more about some of the Java topics. Sometimes, it took a few months of researching a topic before I could write the first sentence on it. Finally, it was always fun to play with Java programs, sometimes for hours, to add them to the book.
Some years ago at a national meeting of mathematicians, many of the conventioneers went about wearing pins which proclaimed, “Mathematics is Not a Spectator Sport”. It is hard to overemphasize the importance of this observation. The idea behind it has been said in many ways by many people; perhaps it was said best by Paul Halmos [Hal67]: The only way to learn mathematics is to do mathematics. In most respects learning mathematics is more like learning to play tennis than learning history. It is principally an activity, and only secondarily a body of knowledge. Although no one would try to learn tennis just by watching others play the game and perhaps reading a book or two about it, thousands of mathematics students in American universities every year attempt to master mathematical subjects by reading textbooks and passively watching their instructors do mathematics on a blackboard. There are, of course, reasons why this is so, but it is unfortunate nevertheless. This book is designed to encourage you to do mathematics. Perhaps the most important thing to know about the structure of this book is that, logically, the appendices come first. The appendices contain a summary of what is generally regarded as prerequisite information that, ideally, one should have before venturing into advanced calculus. In the real world, students’ backgrounds differ enormously. If, at one extreme, you are quite familiar with nearly all of the appended material, you are ready for Chapter 1. Use the appendices for reference and notation. At the other extreme, a very poorly prepared student may profit from spending considerable time working on these sections. In between, where most students find themselves, you have choices. For example, if you are unfamiliar with the distinction between “countable” and “uncountable” sets, you can master the concepts right away, knowing that you will use them later, or you can wait until one of the words crops up in your reading, and learn the concepts when you need them. xvii 英文原版 超清
Antique Comedians of Malidinesia would like to play a new discovered comedy of Aristofanes. Putting it on a stage should be a big surprise for the audience so all the preparations must be kept absolutely secret. The ACM director suspects one of his competitors of reading his correspondece. To prevent other companies from revealing his secret, he decided to use a substitution cipher in all the letters mentioning the new play. Substitution cipher is defined by a substitution table assigning each character of the substitution alphabet another character of the same alphabet. The assignment is a bijection (to each character exactly one character is assigned -- not neccessary different). The director is afraid of disclosing the substitution table and therefore he changes it frequently. After each change he chooses a few words from a dictionary by random, encrypts them and sends them together with an encrypted message. The plain (i.e. non-encrypted) words are sent by a secure channel, not by mail. The recipient of the message can then compare plain and encrypted words and create a new substitution table. Unfortunately, one of the ACM cipher specialists have found that this system is sometimes insecure. Some messages can be decrypted by the rival company even without knowing the plain words. The reason is that when the director chooses the words from the dictionary and encrypts them, he never changes their order (the words in the dictionary are lexicographically sorted). String a1a2 ... ap is lexicografically smaller than b1b2 ... bq if there exists an integer i, i <= p, i <= q, such that aj=bj for each j, 1 <= j < i and ai < bi. The director is interested in which of his messages could be read by the rival company. You are to write a program to determine that. Input Output Sample Input 2 5 6 cebdbac cac ecd dca aba bac cedab 4 4 cca cad aac bca bdac Sample Output abcde Message cannot be decrypted.
Database Systems 1. Fundamental Concepts of Database Database and database technology are having a major impact on the growing use of computers. It is fair to say that database will play a critical role in almost all areas where computers are used, including business, engineering, medicine, law, education, and library science, to name a few. The word "database" is in such common use that we must begin by defining what a database is. Our initial definition is quit general. A database is a collection of related data. By data, we mean known facts that can be recorded and that have implicit meaning. For example, consider the names, telephone numbers, and addresses of all the people you know. You may have recorded this data in an indexed address book, or you may have stored it on a diskette using a personal computer and software such as DBASE III or Lotus 1-2-3. This is a collection of related data with an implicit meaning and hence is a database. The above definition of database is quite general; for example, we may consider the collection of words that make up this page of text to be related data and hence a database. However, the common use of the term database is usually more restricted. A database has the following implicit properties: .A database is a logically coherent collection of data with some inherent meaning. A random assortment of data cannot be referred to as a database. .A database is designed, built, and populated with data for a specific purpose. It has an intended group of users and some preconceived applications in which these users are interested. .A database represents some aspect of the real world, sometimes called the mini world. Changes to the mini world are reflected in the database. In other words, a database has some source from which data are derived, some degree of interaction with events in the real world, and an audience that is actively interested in the contents of the database. A database can be of any size and of varying complexity. Fo
This book is designed to teach you how to use AdonisJs. To get the most out of it, you should have a firm grasp of modern JavaScript and some knowledge of how to work with relational databases and the command line. I explain new and interesting bits of syntax, but this book isn’t primarily about teaching you how to use JavaScript. It’s about teaching you how to build real applications by using AdonisJs. The application we’re going to build is called Threadbear. It’s a play on words, meant to conjure up thoughts of patchy, knitted teddy bears. We’re going to make an application through which sellers can register and upload their knitted patterns and products. Customers will then be able to register and purchase these things. We’re not going to focus much on design. Instead, we’re going to focus on the mechanics of commerce applications. Beyond adding a CSS framework, everything is as the good browser vendors intended. That said, I welcome you to add your own style to the application We’ll create a secure registration and login system. We’ll add profile and product management. We’ll connect the front end to the back end by using WebSockets and the Fetch API. We’ll design a shopping cart in React and we’ll package static files with a custom build chain. Finally, we’ll learn how to deploy the application to a virtual server, and install custom domains and SSL certificates. It is my hope that by the time you are finished reading this book, you’ll know all you need to know in order to build your online business.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值