URAL

来源:互联网 发布:软件著作权登记日期 编辑:程序博客网 时间:2024/06/06 15:01


E - Airport Announcements

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 was late for the connection flight to Petrozavodsk, where a programming camp was to be held. Now he had to wait for long 300 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 that the announcement had been repeated in several languages, but, strangely, there hadn't been Russian among them.
Igor recognized the language of some of the phrases he had heard. He assumed that the number of phrases in the announcement had been the same regardless of the language and that the announcement had been made at most once in each language. Help Igor to find the number of languages in which the announcement was made.
Input
The first line contains the total number n of phrases Igor heard (2 ≤n ≤ 1 000). In the ith of the following n lines you are given the language of theith phrase or the word “unknown” if Igor couldn't recognize the language. It is guaranteed that 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 English letters.
Output
Output the number of languages in which the announcement was made. If there are several answers, list them in ascending order. If there is no solution, output the string “Igor is wrong.”
Example
inputoutput
6englishunknownunknownunknowngermanunknown
2 3 6
4englishfrenchunknownenglish
Igor is wrong.
3zuluzuluzulu


wa!!!看不懂题!

题意是说,他听出来了有n个单词,下面说这n个单词的语言,有的语言不知道,有的语言可以知道,但是连续的x个必然是属于同一种语言,所以所有可能的预言数必然是n的因子,并且将这n个单词以因子为个数分组后,每组为一种语言,如果可以这样分,那么就输出这种语言数,如果不存在那么就输出Igor is wrong.

例如第一组,他可以有1,2,3,6种语言,对应6,3,2,1个为一种语言的单词,

6englishunknownunknownunknowngermanunknown
但6个为一组是错的,因为他听出来了另一种语言;

3个为一组是可以的,前三个单词是English;最后三个是german;一共2种语言

2个为一组,前三个单词是English; 中间两个 (sss某种语言);最后两个german;一共3种语言

同理1个为一组,,6种语言


注意只要是相同 的语言它一定在同一组里面,并且中间不会出现其他的语言,但有unknown是可以的)

#include <iostream>#include<cstdio>#include<vector>#include<string>#include<map>#include<cstring>using namespace std;const int maxn=1000+5;vector<int> yinzi[maxn];map<string,int>num,id;string dui[maxn];vector<int> ch[maxn];vector<int >ans;int vis[maxn];int main(){    for(int i=1;i<=1000;i++)        for(int j=i;j<=1000;j+=i)          yinzi[j].push_back(i);    int n;    cin>>n;    int na=0;    for(int i=0;i<maxn;i++)        ch[i].clear();    num.clear();    int flag=0;    for(int i=1;i<=n;i++)    {        string s;        cin>>s;        num[s]++;        dui[i]=s;        if(s!="unknown"&&num[s]==1)        {               na++;               id[s]=na;        }        if(s!="unknown"&&num[s])        {            if(id[s]!=na)               flag=2;        }        if(s!="unknown")        {           ch[id[s]].push_back(i);        }    }  //  cout<<"na="<<na<<endl;    if(flag==0)    for(int i=0;i<yinzi[n].size();i++)    {        int l=yinzi[n][i];        int jj=0;        memset(vis,0,sizeof(vis));        for(int j=1;j<=n;j+=l)        {            int ng=0;            string g;            for(int k=0;k<l;k++)            {                if(dui[j+k]=="unknown")                    continue;                else                {                     if(!ng)                       {                           g=dui[j+k];                           vis[id[g]]++;                           if(vis[id[g]]>1)                           {                               jj=1;                               break;                           }                       }                     else                     {                        if(dui[j+k]!=g)                        {                            jj=1;                            break;                        }                     }                     ng++;                }            }            if(jj)                break;        }        if(!jj)        {            flag=1;            ans.push_back(n/l);        }    }    if(ans.size()&&flag==1)    for(int i=ans.size()-1;i>=0;i--)    {        cout << ans[i];        if(i==0)            cout<<endl;        else            cout<<" ";    }    else        cout<<"Igor is wrong."<<endl;    return 0;}


原创粉丝点击