• Google Code Jam中国挑战赛:入围赛题目2


    Problem Statement

        

    You are playing a card game, and in your hand, you are holding several cards. Each card has a suit, 'S', 'H', 'D', or 'C', and a value between 1 and 10, inclusive. You may play cards as part of a set, which is three or more cards of the same value, or as part of a run, which is three or more cards of the same suit, in sequential order. (Runs may not wrap, thus, 9-10-1 is not a valid run.) Each card may be played only once.

    For example, "1 S", "1 H" and "1 D" would be a valid set. "2 S", "3 S", and "4 S" would be a valid run.

    You want to play as many cards as possible, maybe in several plays (see example 4). Given a string[] cards representing the cards held in your hand, you are to return an int indicating the maximum number of cards you can play. Each card will be given in the form "value suit" (quotes added for clarity).

    Definition

        
    Class: PlayCards
    Method: maxCards
    Parameters: string[]
    Returns: int
    Method signature: int maxCards(string[] cards)
    (be sure your method is public)
        

    Constraints

    - cards will contain between 0 and 20 elements, inclusive.
    - No two elements of cards will be the same.
    - Each element of cards will be of the form "value suit" (quotes added for clarity).
    - Each number represented will be between 1 and 10, inclusive, with no leading zeroes.
    - Each suit represented will be 'S', 'H', 'D', or 'C'.

    Examples

    0)
        
    {"1 S", "2 S", "3 S"}
    Returns: 3
    We have a run of three cards, which we can play.
    1)
        
    {"4 C", "4 D", "4 S", "3 S", "2 S"}
    Returns: 3
    We can take the 4's as a set, or we can take the 2-3-4 run. Either way, we play 3 cards.
    2)
        
    {"1 S", "2 S", "2 H", "3 H", "3 D", "4 D", "4 C", "5 C", "5 S"}
    Returns: 0
    We've got lots of cards, but no way to put three together.
    3)
        
    {"1 S", "2 S"}
    Returns: 0
    Since we have to play at least three cards at a time, there's nothing to do here.
    4)
        
    {"1 S", "2 S", "10 S", "5 S", "8 S",
     "3 H", "9 H", "6 H", "5 H", "4 H",
     "10 D", "5 D", "7 D", "4 D", "1 D",
     "2 C", "4 C", "5 C", "6 C", "7 C"}
    Returns: 9
    The best we can do is to take the set of 4s, the 5-6-7 C, and the remaining three 5s. We could have taken the 4-5-6-7 of C, or all four 5s, but we would not end up playing as many cards.

    This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

  • 相关阅读:
    用友U8 | 【出纳管理】添加日记账时,为什么日期选不了之前的日期?
    用友U8 | 【总账】结账时提示:该凭证已被别的用户锁定,请稍候在试...
    用友U8 | 【实施导航】实施导航进度条一直显示没完成
    利用Action方法委托重构switch接口
    关于wcf序列化后的压缩示例
    sql常用的命令
    WebBrowser通过cookie自动登录网站
    SqlServer大数据的分区方案
    WebBrowser 登录windows集成验证的网站
    SQL大批量插入数据的方式(多表关联) .
  • 原文地址:https://www.cnblogs.com/whitewin/p/295767.html
Copyright © 2020-2023  润新知