欢迎光临散文网 会员登陆 & 注册

CF 490A - Team Olympiad

2023-06-24 09:58 作者:您是打尖儿还是住店呢  | 我要投稿

The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:

  • ti = 1, if the i-th child is good at programming,

  • ti = 2, if the i-th child is good at maths,

  • ti = 3, if the i-th child is good at PE

Each child happens to be good at exactly one of these three subjects.

The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.

What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?

In the first line output integer w — the largest possible number of teams.


Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.

If no teams can be compiled, print the only line with value w equal to 0.

543 / 5,000

中文:

第一行输出整数 w — 最大可能的团队数。 然后打印w行,每行包含三个数字。 每个三元组代表组成团队的孩子的索引。 您可以按任意顺序打印球队和三元组中的数字。 子项按照其在输入中出现的顺序从 1 到 n 进行编号。 每个孩子只能参加不超过一个团队。 如果有多个解决方案,请打印其中任何一个。 如果无法编译任何团队,则打印 w 值等于 0 的唯一行。

-----------------------------------------------------------------------

其实就是将所有的种类找到,看对应的最小值就是可能组成的队伍数量,然后我是用优先队列保存的索引,依次取出即可,(也可以用ArrayList)下面是代码:


CF 490A - Team Olympiad的评论 (共 条)

分享到微博请遵守国家法律