1889. Airport Announcementstime limit:1.0 Second Memory limit:64 MB Igor was bored of waiting in an airport lounge. Oceanic Airlines, a company he didn ' t like so much, delayed the departure of his flight, so he is late for the connection Flight to Petrozavodsk, where a programming camp is to be held. Now he had-to-wait for long minutes at the airport. Soon He heard a public announcement. Maybe, his flight had been canceled or, maybe, there were discounts on burgers at a nearby Bar-igor couldn ' t-tell for sure . It seemed the announcement had been repeated in several languages, but, strangely, there hadn ' t been Russian among th Em. Igor recognized the language of some of the phrases he had heard. He assumed that's the number of phrases in the announcement had been the same regardless of the language and that the Announ Cement had been made at all once. Help Igor to find the number of languages in which, the announcement was made. Inputthe First line contains the total numberNof phrases Igor heard (2≤N≤1 000). In theITh of the followingNLines you given the language of theITh phrase or the word "unknown" if Igor couldn ' t recognize the language. It is guaranteed this Igor could recognize the language of at least one of the phrases. The name of a language is a string of a length from four to twenty symbols consisting of lowercase 中文 letters. Outputoutput the number of languages in which, the announcement was made. If There is several answers, list them in ascending order. If There is no solution, the output of the string "Igor is wrong." Samples
| input |
Output |
6englishunknownunknownunknowngermanunknown |
2 3 6 |
4englishfrenchunknownenglish |
Igor is wrong. |
3zuluzuluzulu |
1
|
|
Test instructions: There is an announcement that is played in the languages of multiple countries. For example, there are a,b,c three languages. Then this announcement may be aabbcc, or it could be ABC.
Each language represents a word in this language. Each language in the bulletin of the number of words is as many, such as the Aabc,a language more than a word, is not the case.
And the words in each language are continuous and appear only once, as in the second case, Chinese is not contiguous two times, so this situation is not possible.
Unknown can be substituted in any language. Output Igor is wrong if there are no compliance requirements. In many cases, the number of languages in each case is output in ascending order.
For example, the first case:
6
中文版
Unknown
Unknown
Unknown
German
Unknown
English is expressed in E, German is represented by G. My c below is Chinese, and it can actually be any other language.
Output of 2, two languages, the case is eeeggg;
Output of 3, indicating there are three languages, the case is EECCGG
Output of 6, stating there are 6 languages, the situation may be EABCGD which ABCD, each representing a different language
Practice: First discretization, the word is represented as a number, the later processing can be a little faster. Then enumerate all the cases that can be removed by N. The complexity is the square root of N. And then handle every situation.
The total complexity is O (n square root N)
#include <stdio.h> #include <iostream> #include <algorithm> #include <cmath> #include <map > #include <string>using namespace std;string str[1100];string sss;int numb[1100];int yuyan[1100];int vis[1100 ];int n;map<string, int > my;void judge (int i) {if (n%i!=0) return; int lun=n/i;//how many words round. int Biao=-1;int Ok=1;memset (vis,0,sizeof Vis); for (int j=0;j<n;j++) {if (j%lun==0) biao=-1;if (numb[j]!=-1)//detect in this paragraph There are no different words {if (biao==-1) Biao=numb[j];else if (biao!=numb[j]) ok=0;} if ((j+1)%lun==0&&biao!=-1)//detect between different groups there are no different words {if (vis[biao]==0) Vis[biao]=1;else ok=0;} if (!ok) break;} if (OK) yuyan[i]=1; }void solve () {int fang= (int) sqrt ((double) n), for (int i=1;i<=fang;i++)//number of voices {if (n%i==0) {judge (i); Judge (n/i);}} int main () {while (scanf ("%d", &n)!=eof) {my.clear (); int nw=0;int flag=0;for (int i=0;i<n;i++) {Cin>>str[i] if (str[i]!= "Unknown") {if (My.count (Str[i]) ==0) {numb[i]=nw;my[str[i]]=nw++;} else {if (my[str[i]]!=nw-1)//discontinuity appears flag=1;//wrongnumb[i]=nw-1;}} ElsenumB[i]=-1;} memset (yuyan,0,sizeof Yuyan); if (flag) {puts ("Igor is wrong."); Continue;} Else{solve (); int fir=1;for (int i=1;i<=n;i++) {if (Yuyan[i]&&fir) {fir=0;printf ("%d", I);} else if (Yuyan[i]) printf ("%d", I);} if (fir==1) puts ("Igor is wrong."); Else puts ("");}} return 0;}
URAL 1889. Airport Announcements Simulation Questions