Cards
来源:互联网 发布:赛尔网络个人业务 编辑:程序博客网 时间:2024/06/05 02:28
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.
Sample Input
61 5 7 4 4 3
1 36 24 5
410 10 10 10
1 23 4
Hint
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.
用sort快排一下,因为题中保证了n为偶数,只要第一个与最后一个结合,以此类推就行了。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{int pos,x;}s[110];int cmp(node a,node b){return a.x <b.x ;}int main(){int n,i;while(scanf("%d",&n)!=EOF){for(i=0;i<n;i++){ scanf("%d",&s[i].x );s[i].pos =i+1;}sort(s,s+n,cmp);for(i=0;i<n/2;i++)printf("%d %d\n",s[i].pos ,s[n-i-1].pos );}return 0;}
- Cards
- Cards
- Cards
- Cards
- 接着cards
- 15、Cards
- CARDS----置换
- poj_1511Invitation Cards
- 4610 Cards
- Invitation Cards
- Move cards
- Christmas Cards
- Invitation Cards
- [HNOI2008]Cards
- BZOJ_1004 Cards
- Invitation Cards
- 【BZOJ1004】Cards
- poj1511Invitation Cards
- bzoj 4318 OSU! 期望dp
- 关于html部分
- 寻找最近点(快速算法))
- HDU:2546 饭卡(经典01背包+贪心)
- poj1037
- Cards
- 2016.8.15 初中部提高c组模拟赛
- HDU 4283 You Are the One(区间DP)
- spring事务管理器的源码和理解
- 【杭电oj2087】剪花布条
- Merge Two Sorted Lists_Leetcode_#21
- 开发小技巧2
- C语言7
- 51nod 编辑距离 (DP)