zoukankan      html  css  js  c++  java
  • 【POJ2912】【并查集】Rochambeau

    Description

    N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest children are divided into three groups (it is possible that some group is empty). You don’t know who is the judge, or how the children are grouped. Then the children start playing Rochambeau game for M rounds. Each round two children are arbitrarily selected to play Rochambeau for one once, and you will be told the outcome while not knowing which gesture the children presented. It is known that the children in the same group would present the same gesture (hence, two children in the same group always get draw when playing) and different groups for different gestures. The judge would present gesture randomly each time, hence no one knows what gesture the judge would present. Can you guess who is the judge after after the game ends? If you can, after how many rounds can you find out the judge at the earliest?

    Input

    Input contains multiple test cases. Each test case starts with two integers N and M (1 ≤ N ≤ 500, 0 ≤ M ≤ 2,000) in one line, which are the number of children and the number of rounds. Following are M lines, each line contains two integers in [0, N) separated by one symbol. The two integers are the IDs of the two children selected to play Rochambeau for this round. The symbol may be “=”, “>” or “<”, referring to a draw, that first child wins and that second child wins respectively.

    Output

    There is only one line for each test case. If the judge can be found, print the ID of the judge, and the least number of rounds after which the judge can be uniquely determined. If the judge can not be found, or the outcomes of the M rounds of game are inconsistent, print the corresponding message.

    Sample Input

    3 3
    0<1
    1<2
    2<0
    3 5
    0<1
    0>1
    1<2
    1>2
    0<2
    4 4
    0<1
    0>1
    2<3
    2>3
    1 0

    Sample Output

    Can not determine
    Player 1 can be determined to be the judge after 4 lines
    Impossible
    Player 0 can be determined to be the judge after 0 lines

    Source

    Baidu Star 2006 Preliminary 
    Chen, Shixi (xreborner) living in http://fairyair.yeah.net/
    【分析】
    跟食物链基本相同,只不过多一个枚举裁判的过程罢了
  • 相关阅读:
    网页嵌入视频常用方式
    2.4 对字母数字的混合排序
    VC操作Image的三种方法(收集)
    VC 窗口出现白屏闪烁的解决办法
    Invalidate(TRUE)与Invalidate(FALSE)区别(前者会发送WM_ERASEBKGND消息全部刷新,然后使用WM_PAINT消息绘制,而后者只发送WM_PAINT消息)
    QT 文件拖放事件dropEvent和dragEnterEvent
    百用随身系统 Veket Linux
    C#通过属性名称获取(读取)属性值的方法
    搭建一个完整的Java开发环境
    XSD实例
  • 原文地址:https://www.cnblogs.com/hoskey/p/4321926.html
Copyright © 2011-2022 走看看