博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 342 A. Xenia and Divisors
阅读量:6037 次
发布时间:2019-06-20

本文共 2192 字,大约阅读时间需要 7 分钟。

A. Xenia and Divisors
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 test(s)
input
61 1 1 2 2 2
output
-1
input
62 2 1 1 4 6
output
1 2 41 2 6
题目大意:
给你一个数m,然后有m个数arr[i],每个数都<=7 && >=1,让你找满足以下关系的数(3个一组3个一组)
1)a<b<c;
2)a能被b整除,b能被c整除;
解题思路:
首先想到满足关系的三个数
1 2 4
1 2 6
1 3 6
然后再找不属于这三个数的条件,只要去掉不满足条件的就ok了,
不满足条件的:
1)1 的个数必须是m/3;
2)不能有5和7;
3)2 的个数必须大于等于4的个数
4) 6
的个数必须大于等于3的个数
5)2 的个数 + 3的个数  == 6的个数 + 4的个数
然后上代码:
/**Author: ITAKDate: 2015-09-29**/#include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define MM(a) memset(a,0,sizeof(a))typedef long long LL;typedef unsigned long long ULL;const int maxn = 100000+5;const int mod = 1000000007;const double eps = 1e-7;int cmp(int a, int b){ return a > b;}int gcd(int a, int b){ if(b == 0) return a; else return gcd(b, a%b);}int arr[maxn];int data[10];int main(){ int m; scanf("%d",&m); MM(data); for(int i=0; i

转载地址:http://iimhx.baihongyu.com/

你可能感兴趣的文章
JavaScript History对象
查看>>
在 Windows 下安装 Oracle 11g XE (Express Edition)
查看>>
ListView优化
查看>>
【原创】 PostgreSQL 实现MySQL 的auto_increment 字段
查看>>
vs2015添加vc助手
查看>>
检测点1.1
查看>>
android--------阿里 AndFix 热修复
查看>>
java springcloud版b2b2c社交电商spring cloud分布式微服务 (七)高可用的分布式配置中心(Spring Cloud Config)...
查看>>
Oozie与Coordinator调度讲解及系统时区配置与定时触发两种配置方式
查看>>
RGB_YUV_YCbCr
查看>>
tesseract 安装及使用
查看>>
优化SqlServer--数据压缩
查看>>
SharePoint 自定义WebPart之间的连接
查看>>
231. Power of Two
查看>>
control.add()
查看>>
p点到(a,b)点两所在直线的垂点坐标及p点是否在(a,b)两点所在直线上
查看>>
GridView强制换行与自动换行
查看>>
51Nod 1003 阶乘后面0的数量(数学,思维题)
查看>>
Sublime text3中配置Github
查看>>
Getting Started with iOS Development Part10:Customizing your Mobile target's Splash screen
查看>>