【链接】 我是链接,点我呀:)

【题意】

【题解】

最后a,b,c只有以下3种情况
1,2,4
1,2,6
1,3,6
那么用cnt[8]统计每个数字出现的次数.
输出cnt[4]次1,2,4
(如果1或2不够,那么无解
紧接着
如果6的个数和1的个数不同,那么无解
如果2的次数+3的次数和6出现的次数不同,那么无解.
否则
输出cnt[2]个1,2,6
cnt[3]个1,3,6就ok了。
看看有没有输出够n/3组
不够的话就无解(说明有其他无用的数字出现

【代码】

#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
using namespace std; const int N = 1e5; int n,m;
int cnt[10];
vector<pair<int,pair<int,int> > > v; int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n;
for (int i = 1;i <= n;i++) {
int x;
cin >> x;
cnt[x]++;
}
rep1(i,1,cnt[4]) {
v.push_back({1,{2,4}});
if (cnt[1]==0) return cout<<"-1"<<endl,0;
if (cnt[2]==0) return cout<<"-1"<<endl,0;
cnt[1]--;cnt[2]--;
n-=3;
}
cnt[4] = 0;
if (cnt[1]!=cnt[6] || (cnt[2]+cnt[3])!=(cnt[6])){
cout<<"-1"<<endl;
return 0;
}
for (int i = 1;i <= cnt[2];i++){
v.push_back({1,{2,6}});
n-=3;
}
for (int i = 1;i <= cnt[3];i++){
v.push_back({1,{3,6}});
n-=3;
}
if (n!=0) return cout<<-1<<endl,0;
for (auto temp:v){
cout<<temp.first<<' '<<temp.second.first<<' '<<temp.second.second<<endl;
}
return 0;
}

【Codeforces 342A】Xenia and Divisors的更多相关文章

  1. 【Codeforces 339C】Xenia and Weights

    [链接] 我是链接,点我呀:) [题意] 在天平上放砝码 你要在左边放一下然后到右边放一下 一直重复这样放m次 每次你放在其中一边都要让另外一边的重量比你少 你可以用1~10中的某些砝码 问你要怎样放 ...

  2. 【Codeforces 339】Xenia and Bit Operations

    Codeforces 339 D 题意:给定\(2^n​\)个数字,现在把它们进行如下操作: 相邻的两个数取\(or\) 相邻的两个数取\(xor\) 以此类推,直到剩下一个数. 问每次修改一个数字, ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【codeforces 755A】PolandBall and Hypothesis

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 762A】k-th divisor

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 749A】Bachgold Problem

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  8. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  9. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

随机推荐

  1. powerdesigner 16.5 视图的显示

    今天中午为了解说绘图.然后把toolbox跟object brower都关掉了,花了1个小时才找到toolbox 1.object brower显示 直接使用快捷键 ALT+0 2.toolbox(也 ...

  2. 【POJ 1964】 City Game

    [题目链接] http://poj.org/problem?id=1964 [算法] 记f[i]表示第i行最多向上延伸的行数 然后,对于每一行,我们用单调栈计算出这一行向上延伸的最大矩形面积,取最大值 ...

  3. 试用php的ping命令

    使用PHP自动PING IP,校检网络连接是否正常! <?php $server = 'ping kalvin.cn -n 1'; $last_line = exec($server, $arr ...

  4. Django day15 (二) csrf的 跨站请求伪造 与 局部禁用 , 局部使用

    一:  csrf 的跨站请求伪造 二: csrf 的局部禁用 , 局部使用

  5. Jenkins构建项目,JAVA_HOME is not defined correctly

    好久都没有更新了,由于职位调整,开始捣鼓持续集成的东西了.jenkins的基本安装配置网上有很多教程,不用多讲了,就记录下我在使用过程中遇到的一些问题.话说这个jenkins环境以及安装好了有一段时间 ...

  6. [转载]Android平台第三方应用分享到微信开发

    一.申请APPID 微信公共平台和微博分享一样,也需要申请一个ID,来作为调起微信.分享到微信的唯一标识. 申请微信APPID可以到微信平台http://open.weixin.qq.com/app/ ...

  7. supervisord 使用记录

    #supervisor简介 Supervisor是一个 Python 开发的 client/server 系统,可以管理和监控类 UNIX 操作系统上面的进程. #组成部分 supervisord(s ...

  8. JQuery 动态创建表单,并自动提交

    前言:写这个是为了实现使用cookie进行自动登录的功能, 下面的代码是一个元素一个元素进行创建和赋值的, (可以尝试下将所有的html代码(form.input)全部拼好以后放到${ } 中,再进行 ...

  9. 上传预览图片的插件jquery-fileupload

    上传预览图片的插件jquery-fileupload github地址:https://github.com/blueimp/jQuery-File-Upload 中文文档:http://www.jq ...

  10. Android 解决小米手机Android Studio安装app 报错的问题It is possible that this issue is resolved by uninstalling an existi

    Android Studio升级到2.3版本之后,小米手机MIUI8不能运行Android Studio程序,报如下错误: Installation failed with message Faile ...