Codeforces 701A Cards

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/polanwind/article/details/87224691
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <math.h>
#include <string>
#include <algorithm>

using namespace std;

int n;
int temp[105];
bool vis[105];

bool s() {
	for (int i = 1;i <= n;++i) {
		if (vis[i] == false) {
			return true;
		}
	}
	return false;
}

int main() {
	scanf("%d", &n);
	int tot = 0;
	for (int i = 1;i <= n;++i) {
		scanf("%d", &temp[i]);
		tot += temp[i];
	}
	int c = 2 * tot / n;
	while (s()) {
		for (int i = 1;i <= n;++i) {
			for (int j = 1;j <= n;++j) {
				if (i != j && (temp[i] + temp[j] == c)&&vis[i]==false&&vis[j]==false) {
					printf("%d %d\n", i, j);
					vis[i] = true;
					vis[j] = true;
				}
			}
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/polanwind/article/details/87224691