URAL 1889. Airport Announcements 模拟题
2015-03-07 20:51
302 查看
Time limit: 1.0 second |
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 |
每一个语言 代表这个语言的一个单词。 每种语言在公告中的单词数是一样多的,如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; }
相关文章推荐
- URAL - 1889 E - Airport Announcements (好好读题!!!)
- ural 1889 Airport Announcements (暴力模拟)
- 模拟题 ural 1784. Rounders
- Airport Announcements URAL - 1889
- URAL 2046 A - The First Day at School 模拟题
- URAL 1993 This cheeseburger you don't need 模拟题
- ural 1073.Square Country(动态规划)
- URAL 1456 求a模n的阶
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- Open Ural FU Championship 2013 (2013区域赛练习)
- ural 1993 This cheeseburger you don't need
- URAL-1991 The battle near the swamp 水题
- ural 1049. Brave Balloonists(标准分解式,数论)
- HDU 4770 模拟题
- ITAT模拟题
- URAL 1022 Genealogical Tree
- URAL1079:Maximum
- ural 1100. Final Standings(数据结构)
- 百度SEM初级考试模拟题(一)
- Ural 1197 - Lonesome Knight