codeforces 199a
September 12, 2013
CodeForces
link:http://codeforces.com/contest/342/problem/A
恩恩,读错题了。人家是at most 7,我理解成了at lease 7。好欢乐~
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int cnt[8];
int main(void) {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int n, i, j, tmp;
bool flag;
while (~scanf("%d", &n)) {
flag = true;
memset(cnt, 0, sizeof(cnt));
for (i = 0; i < n; ++i) {
scanf("%d", &tmp);
cnt[tmp]++;
}
int sum = cnt[5] + cnt[7];
if (sum > 0) {
printf("-1\n"); continue;
}
int c136 = 0, c126 = 0, c124 = 0;
if (cnt[1] >= cnt[3] && cnt[6] >= cnt[3])
{cnt[1] -= cnt[3]; cnt[6] -= cnt[3]; c136 = cnt[3];}
else flag = false;
if (cnt[1] >= cnt[6] && cnt[2] >= cnt[6])
{cnt[1] -= cnt[6]; cnt[2] -= cnt[6]; c126 = cnt[6];}
else flag = false;
if (cnt[1] >= cnt[4] && cnt[2] >= cnt[4]) {
c124 = cnt[4]; cnt[1] -= cnt[4]; cnt[2] -= cnt[4];}
else flag = false;
if (cnt[1]+cnt[2] > 0) flag = false;
if (flag) {
for (i = 0; i < c136; ++i) printf("1 3 6\n");
for (j = 0; j < c126; ++j) printf("1 2 6\n");
for (i = 0; i < c124; ++i) printf("1 2 4\n");
}
else printf("-1\n");
}
return 0;
}
闲的没事儿干,没事儿做做题=_=
嗨,中村。