基于观察可以发现,双方都一定能保证取到每一列靠近自己的 \(\lfloor \frac{k}{2} \rfloor\) 个元素。

那么一旦一个人想要取另一个人能必然能取的部分,另一个人必然可以不让其取到。

因此,一个人去取对方一定能取到的部分是无意义的。

因此双方的策略必然都是先将靠近自身的 \(\lfloor \frac{k}{2} \rfloor\) 个元素取完,在抢中间剩下的元素。

那么对于最后剩下的元素,每次贪心的选择一定是最优的,因此双方的选择必然都是每次选取当前最大的元素。

那么我们按照这个流程模拟即可,复杂度 \(O(\sum s_i + n \log n)\)。

#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define dep(i, l, r) for (int i = r; i >= l; --i)
const int N = 100 + 5;
int n, m, s, x, A, B, a[N];
int read() {
char c; int x = 0, f = 1;
c = getchar();
while (c > '9' || c < '0') { if(c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int main() {
n = read();
rep(i, 1, n) {
s = read();
if(s & 1) {
rep(j, 1, s / 2) A += read();
a[++m] = read();
rep(j, 1, s / 2) B += read();
}
else {
rep(j, 1, s / 2) A += read();
rep(j, 1, s / 2) B += read();
}
}
sort(a + 1, a + m + 1);
dep(i, 1, m) {
if((m - i + 1) & 1) A += a[i];
else B += a[i];
}
printf("%d %d", A, B);
return 0;
}

CF388C Fox and Card Game的更多相关文章

  1. Codeforces Round #228 (Div. 1) C. Fox and Card Game 博弈

    C. Fox and Card Game 题目连接: http://codeforces.com/contest/388/problem/C Description Fox Ciel is playi ...

  2. Codeforces 388C Fox and Card Game (贪心博弈)

    Codeforces Round #228 (Div. 1) 题目链接:C. Fox and Card Game Fox Ciel is playing a card game with her fr ...

  3. codeforces 388C Fox and Card Game

    刚刚看到这个题感觉是博弈题: 不过有感觉不像,应该是个贪心: 于是就想贪心策略: 举了一个例子: 3 3 1 2 3 4 3 4 1 2 5 4 1 2 5 8 如果他们两个每次都拿对自己最有利的那个 ...

  4. cf E. Fox and Card Game

    http://codeforces.com/contest/389/problem/E 题意:给你n个序列,然后两个人x,y,两个人玩游戏,x从序列的前面取,y从序列的后面取,两个人都想自己得到的数的 ...

  5. Codeforces Round #228 (Div. 2)

    做codeforces以来题目最水的一次 A题: Fox and Number Game 题意:就是用一堆数字来回减,直到减到最小值为止,再把所有最小值加,求这个值 sol: 简单数论题目,直接求所有 ...

  6. Codeforces Round #290 (Div. 2) D. Fox And Jumping dp

    D. Fox And Jumping 题目连接: http://codeforces.com/contest/510/problem/D Description Fox Ciel is playing ...

  7. CodeForces - 512B Fox And Jumping[map优化dp]

    B. Fox And Jumping time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Lesson 3 Please send me a card

    Text Postcards always spoil my holidays. Last summer, I went to Italy. I visited museums and sat in ...

  9. iOS - Card Identification 银行卡号识别

    1.CardIO 识别 框架 GitHub 下载地址 配置 1.把框架整个拉进自己的工程,然后在 TARGETS => Build Phases => Link Binary With L ...

随机推荐

  1. 【Java笔记】applet和html注意

    1.首先记得extends Applet 泪目 2.如果不分包,HTML可以写 <applet code="HelloWorldApplet.class" width=150 ...

  2. Kylin开启Kerberos安全认证

    Kylin开启Kerberos安全认证, 由于Kylin是依赖Hbase启动的, Kylin启动脚本kylin.sh中就是调用的Hbase的启动脚本, 所以当Hbase开启了Keberos之后就等于K ...

  3. CF149D游戏

    题目描述 Petya遇到了一个关于括号序列的问题: 给定一个字符串S,它代表着正确的括号序列,即("(")与 (")")是匹配的.例如:"(())() ...

  4. 安装uiautomator2 + python 自动化环境

    搭建环境: 1.Python版本 37 2.已经搭建到adb (之前试过在python版本几,一直都装不上UIautomator2,报这个错) 安装步骤: 1.到python的安装路径 > 一直 ...

  5. 单例模式(python)

    python 的单例模式需要重写__new__()和 __init__() 需要注意,标识符__和_区别 参考资料: https://www.cnblogs.com/huchong/p/8244279 ...

  6. 第10组 Beta冲刺 总结(组长)

    1.基本情况 组长博客链接:https://www.cnblogs.com/cpandbb/p/14050808.html 答辩总结: ·因为alpha阶段的产品做得偏离了方向,所以beta冲刺大家非 ...

  7. MySQL索引失效的常见场景

    当然请记住,explain是一个好习惯! MySQL索引失效的常见场景 在验证下面的场景时,请准备足够多的数据量,因为数据量少时,MySQL的优化器有时会判定全表扫描无伤大雅,就不会命中索引了. 1. ...

  8. GNU C字节对齐__attribute__((aligned(n))) #pragma pack(n)

    在阅读gnu软件c源代码时,经常会遇到字节对齐相关操作,比如uboot命令相关的代码中,会遇到__attribute__((aligned(n)))扩展关键字,#pragma pack(n)预处理指令 ...

  9. ctfshow web2 web3

    ctfshow web2 1.手动注入题.先用万能密码admin' or 1=1%23,有回显 2.union select注入,2处有回显 3.依次查找数据库.表.字段 得到flag ctfshow ...

  10. 详解__int128

    前言 如果遇到 long long 开不下的情况,可以使用 __int128 来博一把! note :__int128 仅 \(64\) 位 \(GCC G++\) 支持,不在 \(C++\) 标准中 ...