A10529 | Cards
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ cards ( $n$ is even) in the deck. Each card has a positive integer written on it. $n/2$ people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.
Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.
输入格式
The first line of the input contains integer $n$ ( $2<=n<=100$ ) — the number of cards in the deck. It is guaranteed that $n$ is even.
The second line contains the sequence of $n$ positive integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=100$ ), where $a_{i}$ is equal to the number written on the $i$ -th card.
The second line contains the sequence of $n$ positive integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=100$ ), where $a_{i}$ is equal to the number written on the $i$ -th card.
输出格式
Print $n/2$ pairs of integers, the $i$ -th pair denote the cards that should be given to the $i$ -th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.
输入输出样例
输入 #1
6 1 5 7 4 4 3
输出 #1
1 3 6 2 4 5
输入 #2
4 10 10 10 10
输出 #2
1 2 3 4
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to $8$ .
In the second sample, all values $a_{i}$ are equal. Thus, any distribution is acceptable.
In the second sample, all values $a_{i}$ are equal. Thus, any distribution is acceptable.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted