CF77A.Heroes
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The year of 2012 is coming...
According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us mere mortals from the effect of this terrible evil.
The seven great heroes are: amazon Anka, barbarian Chapay, sorceress Cleo, druid Troll, necromancer Dracul, paladin Snowy and a professional hit girl Hexadecimal. Heroes already know how much experience will be given for each of the three megabosses: a for Mephisto, b for Diablo and c for Baal.
Here's the problem: heroes are as much as seven and megabosses are only three! Then our heroes decided to split into three teams, where each team will go to destroy their own megaboss. Each team member will receive a
of experience, rounded down, where x will be the amount of experience for the killed megaboss and y — the number of people in the team.
Heroes do not want to hurt each other's feelings, so they want to split into teams so that the difference between the hero who received the maximum number of experience and the hero who received the minimum number of experience were minimal. Since there can be several divisions into teams, then you need to find the one in which the total amount of liking in teams were maximum.
It is known that some heroes like others. But if hero p likes hero q, this does not mean that the hero q likes hero p. No hero likes himself.
The total amount of liking in teams is the amount of ordered pairs (p, q), such that heroes p and q are in the same group, and hero p likes hero q (but it is not important if hero q likes hero p). In case of heroes p and q likes each other and they are in the same group, this pair should be counted twice, as (p, q) and (q, p).
A team can consist even of a single hero, but it is important that every megaboss was destroyed. All heroes must be involved in the campaign against evil. None of the heroes can be in more than one team.
It is guaranteed that every hero is able to destroy any megaboss alone.
2012 年即将到来……
根据一则古老的乔拉德里坎(Choradrican)传说,就在这一年——2012 年,迪亚波罗(Diablo)及其兄弟墨菲斯托(Mephisto)与巴尔(Baal)将从地狱中逃脱,无数恶魔大军将奴役人类世界。然而,七位英勇无畏的英雄早已齐聚阿拉瑞特山(Mount Arreat)之巅,誓要保护我们这些凡人免遭这滔天邪恶的侵害。
这七位伟大的英雄分别是:亚马逊战士安卡(Anka)、野蛮人查派(Chapay)、法师克莉欧(Cleo)、德鲁伊特罗尔(Troll)、死灵法师德拉库尔(Dracul)、圣骑士斯诺威(Snowy),以及职业女杀手十六进制(Hexadecimal)。英雄们早已知晓,击败三位终极巨兽 Boss 所能获得的经验值分别为:击败墨菲斯托可得 a 点经验,击败迪亚波罗可得 b 点经验,击败巴尔可得 c 点经验。
问题如下:英雄共有七人,而终极巨兽 Boss 却仅有三位!因此,英雄们决定分成三支队伍,每支队伍各自负责讨伐其中一位终极巨兽 Boss。每位队员所获得的经验值为 ⌊yx⌋,其中 x 为被击杀的终极巨兽 Boss 所对应的经验值,y 为该队伍的人数。
英雄们不愿伤害彼此的感情,因此希望将队伍划分得尽可能公平——即令获得最多经验的英雄与获得最少经验的英雄之间的经验差值最小。由于可能存在多种满足该公平性要求的分队方案,因此还需在所有这些方案中,找出队伍内“喜爱总和”最大的一种。
已知部分英雄之间相互喜爱。但若英雄 p 喜欢英雄 q,并不意味着英雄 q 也喜欢英雄 p;且任何英雄均不喜爱自己。
队伍内的“喜爱总和”定义为:所有满足如下条件的有序对 (p,q) 的总数:英雄 p 与 q 处于同一支队伍中,且英雄 p 喜欢英雄 q(至于英雄 q 是否喜欢英雄 p 则无关紧要)。特别地,若英雄 p 与 q 彼此互爱且同处一支队伍,则该互爱关系应被计为两次:一次是 (p,q),另一次是 (q,p)。
一支队伍可以仅由一名英雄组成,但必须确保每位终极巨兽 Boss 均被成功讨伐。所有英雄都必须参与此次对抗邪恶的远征,且每位英雄只能隶属于一支队伍。
题目保证:任意一名英雄均可独自击败任意一位终极巨兽 Boss。
输入格式
The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself.
In the last line are given three integers a, b and c (1 ≤ a, b, c ≤ 2·109), separated by spaces: the experience for Mephisto, the experience for Diablo and experience for Baal.
In all the pretests, except for examples from the statement, the following condition is satisfied: a = b = c.
第一行包含一个非负整数 n(0 ≤ n ≤ 42),表示英雄之间的喜爱关系数量。接下来的 n 行以 “p likes q” 的形式描述喜爱关系,表示英雄 p 喜欢英雄 q(p=q)。每条喜爱关系在输入中恰好出现一次,且没有英雄喜欢自己。
最后一行给出三个整数 a、b 和 c(1 ≤ a,b,c ≤ 2⋅109),以空格分隔:分别表示梅菲斯特、迪亚波罗和巴尔获得的经验值。
在所有预测试用例中(除题目陈述中的示例外),均满足如下条件:a=b=c。
输出格式
Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team).
When calculating the second answer, the team division should satisfy the difference-minimizing contraint. I.e. primary you should minimize the difference in the experience and secondary you should maximize the total amount of liking.
输出两个整数:一是获得最多与最少经验值的两位英雄之间经验差的最小值;二是队伍中总好感度的最大值(即最终被分到同一支队伍中的英雄对之间的友谊数量)。
在计算第二个答案时,队伍划分必须满足“最小化经验差”的约束。也就是说,首要目标是最小化经验差,次要目标是在满足首要目标的前提下最大化总好感度。
输入输出样例
输入#1
3 Troll likes Dracul Dracul likes Anka Snowy likes Hexadecimal 210 200 180
输出#1
30 3
输入#2
2 Anka likes Chapay Chapay likes Anka 10000 50 50
输出#2
1950 2
说明/提示
A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.
第一个示例的说明:第一支队伍应为 Dracul、Troll 和 Anka,第二支队伍应为 Hexadecimal 和 Snowy,第三支队伍应为 Cleo 和 Chapay。
输入解题思路,AI测评打分。不知道怎么写?