URAL 1889. Airport Announcements 模拟题

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




题意:有一个公告是用多个国家的语言播放的。   比如有a,b,c三种语言。  那么这个公告可能是aabbcc,也可以是abc。

每一个语言  代表这个语言的一个单词。 每种语言在公告中的单词数是一样多的,如aabc,a语种 多了一个单词,是不行的。 

而且每种语言 的单词都是连续的,而且仅出现一次,如第二个案例中,english非连续得出现了两次,所以这种情况是不行的。

unknown可以 用任意语言替代。如果没有符合要求的情况,输出 Igor is wrong.。  有且有多种情况的话,输出每一种情况的语种数,按升序输出。


比如第一个案例:

6
english
unknown
unknown
unknown
german
unknown


english 用e 表示,german 用g表示。   我下面的c表示中文,实际也可以是任意其他语言。

输出的2 ,两种语言,情况是  eeeggg;

输出的3,说明有三种语言,情况是 eeccgg   

输出的6,说明有6种语言,情况可能是  eabcgd     其中abcd,各自代表不同的语言


做法:先离散化,把单词表示成数字,后面处理可以更快一点。然后枚举 所有可以被n除的情况。复杂度为 根号n。 然后处理每种情况

总的复杂度为 O(n*根号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;//多少个单词一轮。
	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)//检测 这一段中 有无不同的单词
		{
			if(biao==-1)
				biao=numb[j];
			else if(biao!=numb[j])
				ok=0;
		}
		if((j+1)%lun==0&&biao!=-1)//检测不同组之间有无不同的单词
		{
			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++)//多少种 语音
	{
		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) //间断出现 
						flag=1;// wrong
					numb[i]=nw-1;
				}
			}
			else
				numb[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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的公寓报修管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本公寓报修管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此公寓报修管理系统利用当下成熟完善的Spring Boot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的MySQL数据库进行程序开发。公寓报修管理系统有管理员,住户,维修人员。管理员可以管理住户信息和维修人员信息,可以审核维修人员的请假信息,住户可以申请维修,可以对维修结果评价,维修人员负责住户提交的维修信息,也可以请假。公寓报修管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:公寓报修管理系统;Spring Boot框架;MySQL;自动化;VUE
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值