【Codeforces 342A】Xenia and Divisors
【链接】 我是链接,点我呀:)
【题意】
【题解】
最后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的更多相关文章
- 【Codeforces 339C】Xenia and Weights
[链接] 我是链接,点我呀:) [题意] 在天平上放砝码 你要在左边放一下然后到右边放一下 一直重复这样放m次 每次你放在其中一边都要让另外一边的重量比你少 你可以用1~10中的某些砝码 问你要怎样放 ...
- 【Codeforces 339】Xenia and Bit Operations
Codeforces 339 D 题意:给定\(2^n\)个数字,现在把它们进行如下操作: 相邻的两个数取\(or\) 相邻的两个数取\(xor\) 以此类推,直到剩下一个数. 问每次修改一个数字, ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 755A】PolandBall and Hypothesis
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 762A】k-th divisor
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 749A】Bachgold Problem
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
随机推荐
- 2014百度之星第二题Disk Schedule(双调欧几里得旅行商问题+DP)
Disk Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- RK摄像头移植【转】
本文转载自:http://wiki.t-firefly.com/index.php/Firefly-RK3288/Camera 板载资源 Firefly-RK3288 开发板带有一个 MIPI 摄像头 ...
- P1850 换教室 概率dp
其实说是概率dp,本质上和dp没什么区别,就是把所有可能转移的情况全枚举一下就行了,不过dp方程确实有点长... ps:这个题的floyed我竟然之前写跪了... 题目: 题目描述 对于刚上大学的牛牛 ...
- 复习--二叉树&&树
树是一种很常用的数据结构,日后的学习中会经常碰到运用树的知识. //构造二叉树#include<cstdio> #include<iostream> #include<a ...
- BZOJ1067 [SCOI2007]降雨量 RMQ???
求救!!!神犇帮我瞅瞅呗...未完...调了2个半小时线段树,没调出来,大家帮帮我啊!!! 小詹用st表写. 我的思路就是把中间空着的年份设为无限,然后一点点特判就行了...然而没出来... [SCO ...
- E20170813-ts
explicitly adv. 明白地,明确地;
- Appium + python - swipe滑屏操作实例
方法一: from appium import webdriverfrom time import sleep descred_caps = { "platformName":&q ...
- Spark2.2,IDEA,Maven开发环境搭建附测试
前言: 停滞了一段时间,现在要沉下心来学习点东西,出点货了. 本文没有JavaJDK ScalaSDK和 IDEA的安装过程,网络上会有很多文章介绍这个内容,因此这里就不再赘述. 一.在IDEA上安装 ...
- spring 九种设计模式
spring中常用的设计模式达到九种,我们举例说明: 第一种:简单工厂 又叫做静态工厂方法(StaticFactory Method)模式,但不属于23种GOF设计模式之一. 简单工厂模式的实质是由一 ...
- SQLCE本地数据库
SQLCE是一个标准得关系数据库,可以使用 LINQ 和DateContext来处理本地数据库数据库. 使用SQLCE 要在代码中使用本地数据库功能,需要添加以下命名空间 : using System ...