zoukankan      html  css  js  c++  java
  • Codeforces Fox and Card Game (贪心,排序)

    C. Fox and Card Game
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.

    The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.

    Suppose Ciel and Jiro play optimally, what is the score of the game?

    Input

    The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si(1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.

    Output

    Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.

    Sample test(s)
    input
    2
    1 100
    2 1 10
    output
    101 10
    input
    1
    9 2 8 6 5 9 4 7 1 3
    output
    30 15
    input
    3
    3 1 3 2
    3 5 4 6
    2 8 7
    output
    18 18
    input
    3
    3 1000 1000 1000
    6 1000 1000 1000 1000 1000 1000
    5 1000 1000 1000 1000 1000
    output
    7000 7000
    Note

    In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.

    In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.

    题目的意思是有n堆牌,每一堆牌有si张牌,每张牌都有一个权值,A只能从上面拿牌,B只能从下面拿牌,两个人都采取最优的策略,问最后两个人拿的牌的权值总和是多少。

    可以分析一下,如果

  • 相关阅读:
    怎样在过滤器中读取配置信息?
    怎样将直接数据库中Json字段,映射到Mybatis中的Map类型?
    spring/boot 打包,资源/配置/业务文件分离
    使用VS Code推送代码到GitHub
    Clion下jni配置
    curl post请求总是返回417错误
    ubuntu 12.10 apt-get 源
    如何让git小乌龟工具TortoiseGit记住你的账号密码
    FastCgi与Cgi
    Libevent核心原理
  • 原文地址:https://www.cnblogs.com/clliff/p/4063753.html
Copyright © 2011-2022 走看看