当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

BZOJ2264:Free Goodies

题目描述

Petra and Jan have just received a box full of free goodies, and want to divide the goodies between them. However, it is not easy to do this fairly, since they both value different goodies differently.

To divide the goodies, they have decided upon the following procedure: they choose goodies one by one, in turn, until all the goodies are chosen. A coin is tossed to decide who gets to choose the first goodie.

Petra and Jan have different strategies in deciding what to choose. When faced with a choice, Petra always selects the goodie that is most valuable to her. In case of a tie, she is very considerate and picks the one that is least valuable to Jan. (Since Petra and Jan are good friends, they know exactly how much value the other places on each goodie.)

Jan's strategy, however, consists of maximizing his own final value. He is also very considerate, so if multiple choices lead to the same optimal result, he prefers Petra to have as much final value as possible.

You are given the result of the initial coin toss. After Jan and Petra have finished dividing all the goodies between themselves, what is the total value of the goodies each of them ends up with?

有两个人,分N个物品,每个物品分别对两个人有不同的价值。两个人每次轮流从未被拿走的物品中拿走一个物品。规则是第一个人每次是拿剩下物品中对他而言价值最高的那个,如果有相同的就会拿那个对另外一个人价值最低的物品。另一个人是每次拿那个能保证他最后能拿到价值最大的物品,当然如果有多种选项的话也会优先选择那个对另外一个人价值最低的物品。现在告诉你物品和谁先拿,问最后两人分别能拿到多少?

输入解释

On the first line a positive integer: the number of test cases, at most 100. After that per test case:

One line with an integer n (1 ≤ n ≤ 1 000): the number of goodies.

One line with a string, either "Petra" or "Jan": the person that chooses first.

n lines with two integers pi and ji (0 ≤ pi,ji ≤ 1 000) each: the values that Petra and Jan assign to the i-th goodie, respectively

输出解释

Per test case:

One line with two integers: the value Petra gets and the value Jan gets. Both values must be according to their own valuations

输入样例
3
4
Petra
100 80
70 80
50 80
30 50
4
Petra
10 1
1 10
6 6
4 4
7
Jan
4 1
3 1
2 1
1 1
1 2
1 3
1 4
输出样例
170 130
14 16
9 10
提示

BZPRO Powered by Remmina.
Github Repository
来自acmore.cc的附加信息
bzoj_id 2264
import_source_sha256 6b18cbc0e2e337f03c039af81193b938a8e87c7c8c3a7096cae489619124da59
bzoj_checker_pending False

该题目包含在题集 大视野(八中)OJ 中

题目来源 BZOJ 2264

源链接: LOCAL-BZOJ2264

共提交 0 次

通过率 --%
时间上限 内存上限
1000 MS 128 MB