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

【题意】

【题解】

最后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. 解析HTTP协议六种请求方法

    标准Http协议支持六种请求方法,即: 1,GET 2,HEAD 3,PUT 4,DELETE 5,POST 6,OPTIONS 但其实我们大部分情况下只用到了GET和POST.如果想设计一个符合RE ...

  2. Android View的onTouch和onClick和onLongClick事件

    这三个事件的调用顺序是: onTouch->onLongClick->onClick 先看这三个事件的处理函数: public boolean onTouch(View v, Motion ...

  3. 讲一讲WiFi快连、SmartConfig、SmartConnect

    最近要给公司同事们培训WiFi快连技术,整理了相关资料,也分享在博客这,献给有缘人. 前言 现在的智能硬件产品,以WiFi品类居多,这些WiFi硬件没有人机交互界面,但设备要上网肯定要配置SSID等相 ...

  4. Elias-Fano编码算法——倒排索引压缩用,本质上就是桶排序数据结构思路

    Elias-Fano编码过程如下:把一组整数的最低l位连接在一起,同时把高位以严格单调增的排序划分为桶. Example: 2, 3, 5, 7, 11, 13, 24 Count in unary ...

  5. 完美解决 linux sublime 中文无法输入

    感谢oschina 中几位前辈的分享 下面是我结合自己的情况所配置的具体步骤: 系统环境: ubuntu 12.10 输入法:fcitx fcitx 安装 apt-get install fcitx ...

  6. 操作系统-虚拟机-百科:VM

    ylbtech-操作系统-虚拟机-百科:VM 虚拟机(Virtual Machine)指通过软件模拟的具有完整硬件系统功能的.运行在一个完全隔离环境中的完整计算机系统. 虚拟系统通过生成现有操作系统的 ...

  7. spring 监听器 IntrospectorCleanupListener简介

    转自:https://blog.csdn.net/ywb201314/article/details/51144256 其中JavaBeans Introspector是一个类,位置在Java.bea ...

  8. python使用MySQLdb向mySQL批量插入数据的方法

    该功能通过调用mySQLdb python库中的 cursor.executemany()函数完成批量处理. 今天用这个函数完成了批量插入 例程: def test_insertDB(options) ...

  9. 洛谷P2916 [USACO08NOV]为母牛欢呼(最小生成树)

    P2916 [USACO08NOV]为母牛欢呼Cheering up the C… 题目描述 Farmer John has grown so lazy that he no longer wants ...

  10. 数据通讯与网络 第五版第24章 传输层协议-TCP协议部分要点

    上一博客记录了UDP协议的关键要点,这部分记录TCP协议的关键要点. 24.3 传输控制协议(TRANSMISSION CONTROL PROTOCOL) TCP(Transmission Contr ...