Description
There are n cards (n iseven) 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 thatn is even.
The second line contains the sequence of n positive integersa1, a2, ..., an (1 ≤ ai ≤ 100), whereai is equal to the number written on thei-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
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
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 to8.
In the second sample, all values ai are equal. Thus, any distribution is acceptable.
题意:
输入n张带有数字的纸牌(n为偶数),依照输入次序给每个纸牌进行编号,分给n/2个人,使每个人分得的纸牌上对应的数字之和相等(不是序号和),然后输出。若结果有多个,则输出任意一个。
答案代码:结果AC。
#include <stdio.h>
#define maxn 105
int a[maxn];
struct node
{
int x;
int y;
} b[60],t;
int main()
{
int n,h;
int i,j;
while(scanf("%d",&n) !=EOF)
{
for(i=0;i<n; i++)
scanf("%d",&a[i]);
for(i=0; i<n; i++)
{
b[i].x=a[i];
b[i].y=i;
}
for(i=0; i<n-1; i++)
{
for(j=0; j<n-1-i; j++)
{
if(b[j].x > b[j+1].x)
{
t=b[j];
b[j]=b[j+1];
b[j+1]=t;
}
}
}
for(h=0;h<(n/2);h++)
printf("%d %d\n",b[h].y+1, b[n-h-1].y+1);
}
return 0;
}