CF388C Fox and Card Game
基于观察可以发现,双方都一定能保证取到每一列靠近自己的 \(\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的更多相关文章
- 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 ...
- 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 ...
- codeforces 388C Fox and Card Game
刚刚看到这个题感觉是博弈题: 不过有感觉不像,应该是个贪心: 于是就想贪心策略: 举了一个例子: 3 3 1 2 3 4 3 4 1 2 5 4 1 2 5 8 如果他们两个每次都拿对自己最有利的那个 ...
- cf E. Fox and Card Game
http://codeforces.com/contest/389/problem/E 题意:给你n个序列,然后两个人x,y,两个人玩游戏,x从序列的前面取,y从序列的后面取,两个人都想自己得到的数的 ...
- Codeforces Round #228 (Div. 2)
做codeforces以来题目最水的一次 A题: Fox and Number Game 题意:就是用一堆数字来回减,直到减到最小值为止,再把所有最小值加,求这个值 sol: 简单数论题目,直接求所有 ...
- 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 ...
- 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 ...
- 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 ...
- iOS - Card Identification 银行卡号识别
1.CardIO 识别 框架 GitHub 下载地址 配置 1.把框架整个拉进自己的工程,然后在 TARGETS => Build Phases => Link Binary With L ...
随机推荐
- matplotlib 高阶之path tutorial
目录 Bezier example 用path来画柱状图 随便玩玩 import matplotlib.pyplot as plt from matplotlib.path import Path i ...
- <数据结构>XDOJ314.完全二叉树的子树
问题与解答 问题描述 对一棵完全二叉树,采用自上而下.自左往右的方式从1开始编号,我们已知这个二叉树的最后一个结点是n,现在的问题是结点m所在的子树一共包括多少个结点? 输入格式 输入数据包括多行,每 ...
- 欢迎收看 Flink Forward Asia 2021 峰会直播
在线收看地址:https://developer.aliyun.com/special/ffa2021/live#?utm_content=g_1000316459 Flink 是由 Apache 软 ...
- 初识python: 局部变量、全局变量
定义: 全局变量:在函数一开始定义的变量(全局范围内都可以使用) 局部变量:在函数中定义的变量(只能在函数中使用) 局部变量,例: #局部变量 def chang_name(name): print( ...
- Linux如何对文件内容中的关键字进行查找
如果是用vi打开文件后,在命令行下输入"/关键字"如果是在没有打开文件的前提就用"cat 文件名 | grep "关键字"
- ':app@debug/compileClasspath': Could not find any version that matches com.android.support:appcompat-v7:30.+.
ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not find any version th ...
- PyCharm - 关联mysql失败 - Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually.
时区错误,MySQL默认的时区是UTC时区,比北京时间晚8个小时. 所以要修改mysql的时长 在mysql的命令模式下,输入: set global time_zone='+8:00'; 再次连接成 ...
- javascript错误类型
ECMA-262 定义了下列 7 种错误类型,简单说明如下: Error:普通异常.通常与 throw 语句和 try/catch 语句一起使用. 利用属性 name 可以声明或了 解异常的类型,利用 ...
- [未完] Linux 4.4 USB —— spiflash模拟usb大容量存储设备 调试记录 Gadget Mass Stroage
linux 4.4 USB Gadget Mass Stroage 硬件平台: licheepi nano衍生 调试记录 驱动信息 │ This driver is a replacement for ...
- 网络协议学习笔记(六)http和https
概述 之前讲解了传输层的相关知识,现在讲解一下关于应用层的知识,主要是大家所熟悉的http和https,这2中是咱们最熟悉的协议了,但是也是最不熟悉的协议. HTTP协议:看个新闻原来这么麻烦 HTT ...