博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #228 (Div. 1) C. Fox and Card Game 博弈
阅读量:4556 次
发布时间:2019-06-08

本文共 1671 字,大约阅读时间需要 5 分钟。

C. Fox and Card Game

题目连接:

Description

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 Input

2

1 100
2 1 10

Sample Output

101 10

Hint

题意

有n堆数,第一个人只能从头开始取

第二个人只能从尾部开始取

两个人都采取最优策略

问两个人能够拿到多少分

题解:

对于偶数个的列,一人拿一半

对于奇数的,中间那个会被剩下来

把剩下来的扔到一个vector里面去,排序,然后分奇数偶数拿就好了

代码

#include
using namespace std;int ans1,ans2,n,flag,x;vector
tmp;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&x);flag=x%2;x/=2; for(int j=0;j

转载于:https://www.cnblogs.com/qscqesze/p/5452505.html

你可能感兴趣的文章
【灵异短篇】这个夜晚有点凉
查看>>
一点小问题
查看>>
pytest 10 skip跳过测试用例
查看>>
MVC身份验证及权限管理
查看>>
It was not possible to find any compatible framework version
查看>>
关于8.0.15版本的mysql下载与安装
查看>>
Redis主从复制看这篇就够了
查看>>
洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth 题解
查看>>
(4.20)SQL Server数据库启动过程,以及启动不起来的各种问题的分析及解决技巧...
查看>>
基本数据类型(数字和字符串)
查看>>
函数__装饰器
查看>>
linux system函数分析
查看>>
前端优化措施
查看>>
论学习汉语和学习编程的异同点
查看>>
linux img文件压缩及解压
查看>>
Linux 下的 scp
查看>>
理解同步,异步和延迟脚本
查看>>
MMS源码中异步处理简析
查看>>
XMind 6 如何画流程图
查看>>
final发布评价
查看>>