题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1889
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 |
PS:
题意比较难懂,读了好久, 重复播报的时候是 报的112233这样的,不是123123这样!
代码如下:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int n; string s[1017]; int judge(int t) { for(int i = 0; i < n; i+=t) { int tt = -1; for(int j = i; j < i+t; j++) { if(s[j] != "unknown") { tt = j; break; } } if(tt == -1) continue; for(int j = i; j < i+t; j++) { if(s[j] == "unknown") continue; if(s[tt] != s[j]) { return 0; } } for(int j = i+t; j < n; j++)//只出现一次 { if(s[tt] == s[j]) { return 0; } } } return 1; } int main() { int ans[1017]; scanf("%d",&n); for(int i = 0; i < n; i++) { cin >> s[i]; } int k = 0; for(int i = 1; i <= n; i++) { if(n%i==0)//整除才有可能 { int flag = judge(i);//重复的次数 if(flag) { ans[k++] = n/i; } } } sort(ans,ans+k); if(k == 0) { printf("Igor is wrong.\n"); return 0; } printf("%d",ans[0]); for(int i = 1; i < k; i++) { printf(" %d",ans[i]); } printf("\n"); return 0; }
URAL 1889. Airport Announcements(数学啊 )
原文:http://blog.csdn.net/u012860063/article/details/44131205