A. Cards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
题意:
n
个数,让你找出
思路:直接求和写就好了
ac代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0x7fffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-8
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}
//head
int a[MAXN];
int b[MAXN];
int main()
{
int n;scanf("%d",&n);
mem(b);int sum=0;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]),sum+=a[i];
int ans=sum/(n/2);
for(int i=1;i<=n/2;i++)
{
int c1=0,c2=0;
for(int j=1;j<=n;j++)
{
if(b[j])
continue;
for(int k=1;k<=n;k++)
{
if(b[k]||k==j)
continue;
if(a[j]+a[k]==ans)
{
b[j]=1,b[k]=1;c1=j,c2=k;break;
}
}
if(c1&&c2)
break;
}
printf("%d %d\n",c1,c2);
}
return 0;
}