CodeForces 701A Cards(水水的玩扑克)

http://codeforces.com/problemset/problem/701/A

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 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.

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.



题意:

好多人一块打扑克牌,存在部分两张牌的和相等,问都是哪两张的和与另外两张的和等值。


思路:

统计总和取平均,最后暴力!宇神说了,会暴力是最 low 的%%%%%%%%%%


Code:

#include<stdio.h>
#include<cstring>
const int MYDD=1103;

int c[MYDD];
bool vis[MYDD];//标记该牌是否还存在

int main() {
	int n;
	while(scanf("%d",&n)!=EOF) {
		int sum=0;
		for(int j=1; j<=n; j++) {
			scanf("%d",&c[j]);
			sum+=c[j];
		}

		memset(vis,false,sizeof(vis));
		int a=sum/(n/2);//每个人应该获得的点数
		for(int j=1; j<=n; j++) {
			for(int k=1; k<=n; k++) {
				if(j==k)	continue;//一张牌 
				if(vis[j]||vis[k])	continue;//存在一张牌已经被使用 
				if(c[j]+c[k]==a) {
					printf("%d %d\n",j,k);
					vis[j]=vis[k]=true;
				}
			}
		}
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值