A1054 | Superbull--Silver
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Bessie and her friends are playing hoofball in the annual Superbull
championship, and Farmer John is in charge of making the tournament as
exciting as possible. A total of N (1 <= N <= 2000) teams are playing in the
Superbull. Each team is assigned a distinct integer team ID in the range
1...2^30-1 to distinguish it from the other teams. The Superbull is an
elimination tournament -- after every game, Farmer John chooses which team to
eliminate from the Superbull, and the eliminated team can no longer play in
any more games. The Superbull ends when only one team remains.
Farmer John notices a very unusual property about the scores in matches! In
any game, the combined score of the two teams always ends up being the bitwise
exclusive OR (XOR) of the two team IDs. For example, if teams 12 and 20 were
to play, then 24 points would be scored in that game, since 01100 XOR 10100 =
11000.
Farmer John believes that the more points are scored in a game, the more
exciting the game is. Because of this, he wants to choose a series of games to
be played such that the total number of points scored in the Superbull is
maximized. Please help Farmer John organize the matches.
championship, and Farmer John is in charge of making the tournament as
exciting as possible. A total of N (1 <= N <= 2000) teams are playing in the
Superbull. Each team is assigned a distinct integer team ID in the range
1...2^30-1 to distinguish it from the other teams. The Superbull is an
elimination tournament -- after every game, Farmer John chooses which team to
eliminate from the Superbull, and the eliminated team can no longer play in
any more games. The Superbull ends when only one team remains.
Farmer John notices a very unusual property about the scores in matches! In
any game, the combined score of the two teams always ends up being the bitwise
exclusive OR (XOR) of the two team IDs. For example, if teams 12 and 20 were
to play, then 24 points would be scored in that game, since 01100 XOR 10100 =
11000.
Farmer John believes that the more points are scored in a game, the more
exciting the game is. Because of this, he wants to choose a series of games to
be played such that the total number of points scored in the Superbull is
maximized. Please help Farmer John organize the matches.
输入格式
The first line contains the single integer N. The following N lines contain
the N team IDs.
the N team IDs.
输出格式
Output the maximum possible number of points that can be scored in the
Superbull.
Superbull.
输入输出样例
输入 #1
4 3 6 9 10
输出 #1
37
OUTPUT DETAILS: One way to achieve 37 is as follows: FJ matches teams 3 and 9,
and decides that 9 wins, so teams 6, 9, and 10 are left in the tournament. He
then matches teams 6 and 9, and lets team 6 win. Teams 6 and 10 are then left
in the tournament. Finally, teams 6 and 10 face off, and team 10 wins. The
total number of points scored is (3 XOR 9) + (6 XOR 9) + (6 XOR 10) = 10 + 15
+ 12 = 37.
NOTE: The bitwise exclusive OR operation, commonly denoted by the ^ symbol, is
a bitwise operation that performs the logical exclusive OR operation on each
position in two binary integers. The result in each position is 1 if only the
first bit is 1 or only the second bit is 1, but is 0 if both bits are 0 or
both are 1. For example: 10100 (decimal 20) XOR 01100 (decimal 12) = 11000
(decimal 24)
and decides that 9 wins, so teams 6, 9, and 10 are left in the tournament. He
then matches teams 6 and 9, and lets team 6 win. Teams 6 and 10 are then left
in the tournament. Finally, teams 6 and 10 face off, and team 10 wins. The
total number of points scored is (3 XOR 9) + (6 XOR 9) + (6 XOR 10) = 10 + 15
+ 12 = 37.
NOTE: The bitwise exclusive OR operation, commonly denoted by the ^ symbol, is
a bitwise operation that performs the logical exclusive OR operation on each
position in two binary integers. The result in each position is 1 if only the
first bit is 1 or only the second bit is 1, but is 0 if both bits are 0 or
both are 1. For example: 10100 (decimal 20) XOR 01100 (decimal 12) = 11000
(decimal 24)
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted