URAL 1711. Code Names (数学啊 )

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

1711. Code Names

Time limit: 0.5 second

Memory limit: 64 MB

Imagine that you have to prepare a problem set for the forthcoming programming contest and you have already chosen the problems you will use in it. Before you start writing problem statements, preparing
tests, and writing author solutions, you must give code names to all the problems.

A code name is a string that uniquely identifies the problem. For example, instead of saying “problem about the cipher grille”, you can simply say “problem grille.”

The problems in a problem set are arranged according to the lexicographical order of their code names. However, the program committee wants to get a fixed order of the problems. For example, the easiest
problem should be put on the first place so that all the teams will be able to find it, or the letter D can be assigned to a really Difficult problem. Therefore, to obtain some predefined order of the problems in the problem set, the program committee needs
to carefully choose the code names. This is just what you have to do.

To make your task easier, the program committee proposed three variants of the code name for each of the n problems in the problem set. You only have to choose an appropriate variant for each
problem.

Input

The first line contains the number n of problems in the problem set (1 ≤ n ≤ 16). The i-th of the following n lines contains three possible code names for the i-th
problem. The variants are separated with a space. The last line contains a permutation of the numbers from 1 to n. This is the order in which the problems must be arranged in the problem set. Each code name consists of lowercase Latin letters and
its length is at most 20. All the code names are different.

Output

Output n lines. The i-th line should contain the code name of the problem that will have number i in the problem set. If there are several possible answers, output any of
them. If it is impossible to choose the code names as required, output “IMPOSSIBLE”.

Samples

input output
11
cipher grille kamkohob
names codenames codes
newtests rejudge timus
size volume summit
watchmen braineater twosides
solution random yesorno
keywords subversion commands
bosses shooting shaitan
game strategy playgame
mnemonic palindromes bestname
eligibility rectangle rules
2 1 7 10 9 6 11 3 8 4 5
codenames
grille
keywords
mnemonic
playgame
random
rectangle
rejudge
shaitan
volume
watchmen
3
problems in the
first sample are
ordered not randomly
1 2 3
IMPOSSIBLE

代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
    int n;
    string s[27][27];
    while(~scanf("%d",&n))
    {
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < 3; j++)
            {
                cin >> s[i][j];
            }
            sort(s[i],s[i]+3);
//            for(int j = 0; j < 3; j++)
//            {
//                cout<<s[i][j]<<endl;
//            }
        }
        int num;
        string ans[27];
        string tt="";
        int flag = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%d",&num);
            num--;
            if(i == 0)//最小的
            {
                tt = s[num][0];
                ans[0] = tt;
                continue;
            }
            //cout<<"tt:"<<tt<<endl;
            int mark = 0;
            for(int j = 0; j < 3; j++)
            {
                mark = 0;
                if(s[num][j] > tt)
                {
                    mark = 1;
                    tt = s[num][j];
                    //cout<<"tt:"<<tt<<endl;
                    ans[i] = s[num][j];
                    break;
                }
            }
            if(mark == 0)
            {
                flag = 1;
            }
        }
        if(flag == 1)
        {
            printf("IMPOSSIBLE\n");
            continue;
        }
        for(int i = 0; i < n; i++)
        {
            cout<<ans[i]<<endl;
        }
    }
    return 0;
}
时间: 2024-11-05 09:36:18

URAL 1711. Code Names (数学啊 )的相关文章

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 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 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 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

URAL 1295. Crazy Notions(数学啊 &amp; 找规律)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1295 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 th