URAL 1889. Airport Announcements(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1889

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

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;
}
时间: 2024-11-05 06:50:59

URAL 1889. Airport Announcements(数学啊 )的相关文章

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 t

URAL 2003. Simple Magic(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2003 2003. Simple Magic Time limit: 1.0 second Memory limit: 64 MB Do you think that magic is simple? That some hand-waving and muttering incomprehensible blubber is enough to conjure wonderful garden

URAL 1515. Cashmaster (数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1515 Background Once upon a time former petty bureaucrat, nowadays the Minister of Finance of the Soviet Federation, Victor Thiefton considered, that he had stolen so much money during the first half

URAL 1718 . Rejudge(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1718 1718. Rejudge Time limit: 0.5 second Memory limit: 64 MB At three o'clock in the morning Sasha (aka Sandro) discovered that there were only seven tests for one of the problems in the first volume

URAL 1295 Crazy Notions 数学 找规律

1295. Crazy Notions Time limit: 0.5 second Memory limit: 64 MB For five days robot-loader JK546L54p has been buried under the thick layer of the Sibelian plutonium slag. The terrible strike of the atmospheric electricity has led to the depressurizati

URAL 2047 Maths (数学)

对于一个数来说,它的除数是确定的,那么它的前驱也是确定的,而起点只能是1或2,所以只要类似筛法先预处理出每个数的除数个数 ,然后递推出每个数往前的延伸的链长,更新最大长度,记录对应数字.找到maxn以后,根据最后一个数找到前驱,并记录到ans数组中. 代码来自队友 #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<vector> #

URAL 1823. Ideal Gas 数学,分类

1823. Ideal Gas Time limit: 0.5 second Memory limit: 64 MB Many of you know the universal method of solving simple physics problems: you have to find in a textbook an identity in which you know the values of all the quantities except for one, substit

URAL 1826. Minefield(数学啊 递归)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1826 1826. Minefield Time limit: 0.5 second Memory limit: 64 MB To fulfill an assignment, a reconnaissance group of n people must cross the enemy's minefield. Since the group has only one mine detecto

URAL 1731. Dill(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1731 1731. Dill Time limit: 0.5 second Memory limit: 64 MB Ivan Vasil'evich likes to work in his garden. Once he heard that dill was a very beautiful and healthy crop and planted his whole garden with