可恶的Airport Announcements(http://acm.timus.ru/problem.aspx?space=1&num=1889 ),终于AC了,加上下午训练赛的三个小时,总共5个小时啊。期间,WA四次,竟然还CE了一次,是忘了加头文件了......还是自己的编程习惯不好.......直接导致我以为是string提交不可以,改回来了原始的char[],不过还在这样修改过后AC了.......发现忘了加头文件之后,加上头文件,也AC了,终于皆大欢喜了!
终于可以安心睡觉了,为即将到来的明天的骑行之旅庆祝!
#define MAXN 1002
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
string str[MAXN],strtem[MAXN];
int cnt[MAXN],cntnum=1;
void solve()
{
int n,i,k,g,j,r,l=0,counter=0,m;
bool flag1,flag2,flag=false;
cin >> n;
for(i=1;i<=n;i++){
cin>>str[i];
if(str[i]=="unknown") flag=true;
for(j=1;j<=l;j++)
if(strtem[j]==str[i]) break;
if(j>l && str[i]!="unknown"){ //统计不同语言的数目
strtem[++l]=str[i];
counter++;
}
}
//cout<<"counter="<<counter<<endl;
if(counter==0) { for(i=1;i<=n;i++) if(n%i==0) cnt[cntnum++]=i; } //全部是unknown的情况
else if(counter==1 && !flag) { cnt[cntnum++]=1;} //全部是一种语言的情况
else{
for(i=counter;i<=n;i++)
{
flag1=true;flag2=true;
if(n%i) continue;
m=n/i;
for(j=0;j<i;j++)
{
for(k=j*m+1;k<=(j+1)*m;k++){ //在每组内部进行判断是否有不同的语言
for(g=k+1;g<=(j+1)*m;g++){
if(str[g]!=str[k] && str[k]!="unknown" && str[g]!="unknown" ){
flag1=false;break;
}
}
if(!flag1) break;
}
//if(flag1) cout<<"i="<<i<<" nihao "<<endl;
//cout<<""
if(j<i-1) //判断各组之间是否有相同的语言
{
for(k=j*m+1;k<=(j+1)*m;k++)
for(r=j+1;r<i;r++){
for(g=r*m+1;g<=(r+1)*m;g++){
if(str[g]==str[k] && str[k]!="unknown"){
flag2=false;break;
}
}
if(!flag2) break;
}
if(!flag2) break;
}
}
if(flag1&&flag2) cnt[cntnum++]=i; //两种情况同时成立,储存下来
}
}
if(cntnum==1)
cout<<"Igor is wrong."<<endl;
else
{
for(i=1;i<cntnum-1;i++)
cout<<cnt[i]<<" ";
cout<<cnt[cntnum-1]<<endl;
}
}
int main()
{
solve();
return 0;
}
部分测试数据:
4
unknown
unknown
unknown
unknown
Answer: 1 2 4
2
unknown
unknown
Answer: 1 2
12
A
B
unknown
unknown
unknown
unknown
unknown
unknown
unknown
unknown
unknown
unknown
Answer: 12
4
A
B
C
D
Answer: 4
8
A
A
B
B
unknown
unknown
unknown
unknown
Answer: 4
6
A
A
B
B
unknown
unknown
Answer: 3
6
unknown
A
A
B
unknown
B
Answer: 2
6
A
unknown
unknown
A
unknown
unknown
Answer: 1
6
A
unknown
A
unknown
unknown
unknown
Answer: 1 2
4
A
A
A
B
Answer: Igor is wrong.