URAL1889

1889. Airport Announcements

Time 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 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.”

Samples

input output
6
english
unknown
unknown
unknown
german
unknown
2 3 6
4
english
french
unknown
english
Igor is wrong.
3
zulu
zulu
zulu
1
Problem Author: Denis Dublennykh

Problem Source: NEERC 2011, Eastern subregional contest




细节题:

首先,从上到下,有几种语言,每种语言的行数一样,也就是说,可能性只有n的约数,因为n<=1000,所以并不会超时,不过这套题有很多的bug,改了六七遍,最后终于ac了。

对于每一个n/i来说,里面的语言只能有一种或者是未知的unknown。

其次,因为一开始我的代码的每一个分块是没有联系的,后来发现了这个问题。。。。

所以,任意的分块他们的语言是不能一样的,比如,english,unknown,unknown,english。这样的分块就不能是2.

所以要求出每一个分块的语言,如果有相同的就不行了。。。



#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <vector>
using namespace std;
string a[1010];
int n;
bool solve(int x)         求分块
{
    for(int i=1; i<=n; i+=n/x)
    {
        set<string> p;
        for(int j=i; j<i+n/x; j++)
        {
            string s=a[j];
            if(s!="unknown")
            {
                if(!p.count(s)&&!p.empty()) return false;  判断能否正确分块
                p.insert(s);
            }
        }
    }
    for(int i=n/x;i<=n;i+=n/x)
    {
        if(a[i]==a[i+1]&&(a[i]!="unknown"&&a[i+1]!="unknown")) return false;
    }
    return true;
}
int main()
{
    while(cin>>n)
    {
        vector<string>vec;
        for(int i=1; i<=n; i++)
        {
            cin>>a[i];
            if(a[i]!="unknown")vec.push_back(a[i]);  进行特殊情况的判断,即两种相同的语言之间有另一种语言
        }
        bool ok=true;
        for(int i=0; i<vec.size(); i++)
        {
            for(int j=i+1; j<vec.size(); j++)
            {
                if(vec[j]==vec[i])
                {
                    for(int l=i+1; l<j; l++)
                    {
                        if(vec[l]!=vec[i]){ ok=false; break;}

                    }
                }
            }
        }
        if(ok==false)
        {
            cout<<"Igor is wrong."<<endl;  特殊情况的处理
        }
        else
        {
            set<int>z; string b[1010];
            for(int i=1;i<=n;i++) b[i]="unknown";
            for(int i=1; i<n; i++)
            {
                if(n%i==0)
                {
                    if(i==1)
                    {
                        if(solve(i)) z.insert(i);
                    }
                    else
                    {
                       if(solve(i))
                    {
                        int sum=0; bool f=true;
                        for(int j=1;j<=n;j+=n/i)
                        {
                            bool o=true;
                            for(int k=j;k<j+n/i;k++)
                            {
                                if(a[k]!="unknown") {b[++sum]=a[k];o=false;break;}
                            }
                            if(o)b[++sum]="unknown";
                        }
                        for(int k=1;k<=sum;k++)
                        {
                            for(int j=k+1;j<=sum;j++)
                            {
                                if(b[k]==b[j]&&(b[k]!="unknown"&&b[j]!="unknown")) {f=false; break;}
                            }
                        }
                        if(f)z.insert(i);}    如果不同的分块有相同的语言就不行了
                    }
                }
            }
            set<string>p1;
            bool flag=true;
            for(int i=1; i<=n; i++)
            {
                if(a[i]=="unknown") continue;
                else if(!p1.count(a[i])) p1.insert(a[i]);
                else{flag=false;}
            }
            if(flag) z.insert(n);对于n的情况的特殊处理
            if(!z.size()) cout<<"Igor is wrong."<<endl;
            else
            {
                set<int>::iterator it=z.begin();
                cout<<*it;
                for(it=++z.begin(); it!=z.end(); ++it)
                    cout<<" "<<*it;
                cout<<endl;     输出
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的公寓报修管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本公寓报修管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此公寓报修管理系统利用当下成熟完善的Spring Boot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的MySQL数据库进行程序开发。公寓报修管理系统有管理员,住户,维修人员。管理员可以管理住户信息和维修人员信息,可以审核维修人员的请假信息,住户可以申请维修,可以对维修结果评价,维修人员负责住户提交的维修信息,也可以请假。公寓报修管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:公寓报修管理系统;Spring Boot框架;MySQL;自动化;VUE
毕业设计,基于SpringBoot+Vue+MySQL开发的社区医院管理系统,源码+数据库+毕业论文+视频演示 信息数据从传统到当代,是一直在变革当中,突如其来的互联网让传统的信息管理看到了革命性的曙光,因为传统信息管理从时效性,还是安全性,还是可操作性等各个方面来讲,遇到了互联网时代才发现能补上自古以来的短板,有效的提升管理的效率和业务水平。传统的管理模式,时间越久管理的内容越多,也需要更多的人来对数据进行整理,并且数据的汇总查询方面效率也是极其的低下,并且数据安全方面永远不会保证安全性能。结合数据内容管理的种种缺点,在互联网时代都可以得到有效的补充。结合先进的互联网技术,开发符合需求的软件,让数据内容管理不管是从录入的及时性,查看的及时性还是汇总分析的及时性,都能让正确率达到最高,管理更加的科学和便捷。本次开发的社区医院管理系统实现了病例信息、字典表、家庭医生、健康档案、就诊信息、前台、药品、用户、用户、用户表等功能。系统用到了关系型数据库中王者MySql作为系统的数据库,有效的对数据进行安全的存储,有效的备份,对数据可靠性方面得到了保证。并且程序也具备程序需求的所有功能,使得操作性还是安全性都大大提高,让社区医院管理系统更能从理念走到现实,确确实实的让人们提升信息处理效率。 关键字:社区医院管理系统;信息管理,时效性,安全性,MySql
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值