zoukankan      html  css  js  c++  java
  • poj3195 Generalized Matrioshkas(瞎搞题翻译)

    译文:
    题目描述

    弗拉基米尔多年以来一直从事俄罗斯套娃这门工艺,俄罗斯套娃是俄罗斯传统工艺的精髓。俄罗斯套娃,就是一种可以分成两半的娃娃,分开之后可以在里面找到另一个比ta小一号的娃娃,一直重复这个操作,直到最后一个娃娃无法被分开了。

    最近,弗拉基米尔意识到俄罗斯娃娃的创意可以推广到嵌套玩具。ta设计了一种嵌套型的玩具,然而和俄罗斯套娃有一点不同:每个娃娃里面可能有不止一个娃娃。这是一个全新的功能,弗拉基米尔想向大众推广一下。

    弗拉基米尔开发了一种符号来描述应该如何构造嵌套玩具。
    每个玩具根据其大小用一个正整数表示。更准确地说应该是:如果打开一个大小为m的玩具,在里面的玩具大小分别是n1,n2,…,nr,ta们必须满足n1 + n2 +…+ nr < m。如果是这样的话,我们说玩具m直接包含玩具n1,n2,…,nr。应该明确的一点是:那些包含在n1,n2,…,nr里的玩具不算是直接包含在m里的。

    一个最一般的嵌套玩具可以表示成一个非空的非零整数序列的形式:
    a1 a2 … aN
    玩具k用序列中的两个整数−k和k来表示,负数在前,正数在后。
    例如,序列:
    −9 −7 −2 2 −3 −2 −1 1 2 3 7 9
    代表一个嵌套玩具是由六个玩具,即1,2(两个),3,7和9。注意,玩具7直接包含了玩具2和3。注意,第一个玩具2是单独一个,第二个玩具2中包含了玩具1。如果认为第一个-2是和最后一个2搭配,那就是错误的理解。

    下面的序列就不是一个合格的嵌套玩具:
    −9 −7 −2 2 −3 −1 −2 2 1 3 7 9
    因为玩具2比玩具1大,玩具1是不能包含玩具2的。
    −9 −7 −2 2 −3 −2 −1 1 2 3 7 −2 2 9
    因为7和2不能同时放在9中。
    −9 −7 −2 2 −3 −1 −2 3 2 1 7 9
    因为玩具3存在不合法嵌套。

    你的任务就是编写一个程序来帮助弗拉基米尔判断设计是否成功。

    输入
    输入包含多个测试点,每一个测试点都在单独的一行中,每个测试点是一个非零的整数序列,每一个数保证绝对值小于1e7。

    输出
    输入和输出要对应起来,按照输入顺序输出。
    每个测试点的答案必须是一下的形式之一:
    如果输入描述了一个合法的嵌套玩具matrioshka,那么输出:
    :-)Matrioshka !
    否则,答案应该是:
    :-( Try again.

    样例输入
    -9 -7 -2 2 -3 -2 -1 1 2 3 7 9
    -9 -7 -2 2 -3 -1 -2 2 1 3 7 9
    -9 -7 -2 2 -3 -1 -2 3 2 1 7 9
    -100 -50 -6 6 50 100
    -100 -50 -6 6 45 100
    -10 -5 -2 2 5 -4 -3 3 4 10
    -9 -5 -2 2 5 -4 -3 3 4 9

    样例输出
    :-) Matrioshka!
    :-( Try again.
    :-( Try again.
    :-) Matrioshka!
    :-( Try again.
    :-) Matrioshka!
    :-( Try again.

    原文:

    Description

    Vladimir worked for years making matrioshkas, those nesting dolls that certainly represent truly Russian craft. A matrioshka is a doll that may be opened in two halves, so that one finds another doll inside. Then this doll may be opened to find another one inside it. This can be repeated several times, till a final doll – that cannot be opened – is reached.

    Recently, Vladimir realized that the idea of nesting dolls might be generalized to nesting toys. Indeed, he has designed toys that contain toys but in a more general sense. One of these toys may be opened in two halves and it may have more than one toy inside it. That is the new feature that Vladimir wants to introduce in his new line of toys.

    Vladimir has developed a notation to describe how nesting toys should be constructed. A toy is represented with a positive integer, according to its size. More precisely: if when opening the toy represented by m we find the toys represented by n1, n2, …, nr, it must be true that n1 + n2 + … + nr < m. And if this is the case, we say that toy m contains directly the toys n1, n2, …, nr. It should be clear that toys that may be contained in any of the toys n1, n2, …, nr are not considered as directly contained in the toy m.

    A generalized matrioshka is denoted with a non-empty sequence of non zero integers of the form:

    a1 a2 … aN
    such that toy k is represented in the sequence with two integers −k and k, with the negative one occurring in the sequence first that the positive one.

    For example, the sequence

    −9 −7 −2 2 −3 −2 −1 1 2 3 7 9
    represents a generalized matrioshka conformed by six toys, namely, 1, 2 (twice), 3, 7 and 9. Note that toy 7 contains directly toys 2 and 3. Note that the first copy of toy 2 occurs left from the second one and that the second copy contains directly a toy 1. It would be wrong to understand that the first −2 and the last 2 should be paired.

    On the other hand, the following sequences do not describe generalized matrioshkas:

    −9 −7 −2 2 −3 −1 −2 2 1 3 7 9
    because toy 2 is bigger than toy 1 and cannot be allocated inside it.

    −9 −7 −2 2 −3 −2 −1 1 2 3 7 −2 2 9
    because 7 and 2 may not be allocated together inside 9.

    −9 −7 −2 2 −3 −1 −2 3 2 1 7 9
    because there is a nesting problem within toy 3.

    Your problem is to write a program to help Vladimir telling good designs from bad ones.

    Input

    The input file contains several test cases, each one of them in a separate line. Each test case is a sequence of non zero integers, each one with an absolute value less than 107.

    Output

    Output texts for each input case are presented in the same order that input is read.

    For each test case the answer must be a line of the form

    :-) Matrioshka!

    if the design describes a generalized matrioshka. In other case, the answer should be of the form

    :-( Try again.

    Sample Input
    -9 -7 -2 2 -3 -2 -1 1 2 3 7 9
    -9 -7 -2 2 -3 -1 -2 2 1 3 7 9
    -9 -7 -2 2 -3 -1 -2 3 2 1 7 9
    -100 -50 -6 6 50 100
    -100 -50 -6 6 45 100
    -10 -5 -2 2 5 -4 -3 3 4 10
    -9 -5 -2 2 5 -4 -3 3 4 9

    Sample Output
    :-) Matrioshka!
    :-( Try again.
    :-( Try again.
    :-) Matrioshka!
    :-( Try again.
    :-) Matrioshka!
    :-( Try again.

  • 相关阅读:
    Python基本数据类型
    DNS服务
    在浏览器地址栏输入百度网址之后的故事(面试必考)
    C++对象的赋值和复制
    C++区别于其他语言的知识点总结
    SQL连接查询(最全面)
    源码堆栈信息保存 到此一游
    linux 内核调试之关键函数名记要
    记几个命令 转
    JS 奇淫巧技 转
  • 原文地址:https://www.cnblogs.com/wutongtong3117/p/7673275.html
Copyright © 2011-2022 走看看