Codeforces Round #364 (Div. 2) A
2016-07-23 14:29
337 查看
Description
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.
Input
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 a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is equal to the number written on the i-th card.
Output
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.
Examples
input
output
input
output
Note
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 ai are equal. Thus, any distribution is acceptable.
这个,从大到小排序,然后取头尾就行
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.
Input
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 a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is equal to the number written on the i-th card.
Output
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.
Examples
input
6 1 5 7 4 4 3
output
1 3 6 2 4 5
input
4 10 10 10 10
output
1 2 3 4
Note
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 ai are equal. Thus, any distribution is acceptable.
这个,从大到小排序,然后取头尾就行
#include<bits/stdc++.h> using namespace std; int n,m; struct P { int i,num; }He[105]; bool cmd(P x,P y) { return x.num<y.num; } int main() { int n; cin>>n; for(int i=1;i<=n;i++) { cin>>He[i].num; He[i].i=i; } sort(He+1,He+n+1,cmd); for(int i=1;i<=n/2;i++) { cout<<He[i].i<<" "<<He[n-i+1].i<<endl; } return 0; }
相关文章推荐
- AbstractAxis QML 类型翻译
- 10Mbps以太网的帧长度
- SQL练习题
- JAVA设计模式---模板方法
- leetcode_c++:栈: Basic Calculator(224)
- Ubuntu 14.04 LTS + Qt 5.2.1 源码编译搭建环境
- 棋盘游戏(三子棋)
- ViewGroup.LayoutParams
- 嵌入式 Linux下永久生效环境变量bashrc
- 多媒体文件格式之FLV
- 第一周学习笔记4
- poj 1088 / 3624两道简单DP
- iOS笔记 页面切换 CATransition Animation动画
- webpack知识梳理
- cocos2dx.3.x之重要类分析(1)——Ref
- Ubuntu解压缩zip,tar,tar.gz,tar.bz2
- vim编辑器重新打开文本,回到上次编辑的位置
- ContentProvider 操作小实例 (了解)
- iOS - 小文件下载篇(边下载边写入文件)
- Windows应用程序对键盘与鼠标的响应