CodeForces 342A

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121074#problem/A

A - Xenia and Divisors
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  CodeForces 342A

Description

Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:

  • a < b < c;
  • a divides bb divides c.

Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has  groups of three.

Help Xenia, find the required partition or else say that it doesn't exist.

Input

The first line contains integer n(3 ≤ n ≤ 99999) — the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.

It is guaranteed that n is divisible by 3.

Output

If the required partition exists, print  groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.

If there is no solution, print -1.

Sample Input

Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6


题意: n个正整数数(n一定是3的倍数)(每个数不超过7)3个一组分成n/3组,每组三个数分别是a,b,c. abc满足以下条件: a思路: 结果只有三种情况, 

124 

126

136

要输出最终结果先要判断这n个数是否能被这样分开  因为只有三种情况所以这n个数只能存在12346这五个数 必须满足以下条件:

令d(x)表示x的个数

1 d(1)=n/3;

2 d(2)+d(3)=n/3;

3 d(4)+d(6)=n/3;

*4 d(2)>d(4)  d(6)>d(3);

这些条件是为了保证这n个数能被分成上述的三种情况,必须是上述三种情况的充分条件条件可以适当更多更苛刻但不能少

比赛是就是没加条件4( 出错数据 6     1 1 3 3 4 4 )出错

#include
#include
#include
#include
#include
using namespace std;
int a[7];
int main(){
    int n,t;
    while(~scanf("%d",&n)){
        memset(a,0,sizeof a);
        for(int i=0;ia[2]||a[3]>a[6]){cout<<"-1\n";continue;}

        for(int i=0;i



你可能感兴趣的:(CodeForces 342A)