URAL - 1889 E - Airport Announcements (好好读题!!!)

43 篇文章 0 订阅


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 the ith 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
6
english
unknown
unknown
unknown
german
unknown
2 3 6
4
english
french
unknown
english
Igor is wrong.
3
zulu
zulu
zulu


wa!!!看不懂题!

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

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

6
english
unknown
unknown
unknown
german
unknown
但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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值