要点

  • 可以贪心选数量最多的那三个构造
  • 二分的话里面的check我不太会。正解是既然当前答案为\(k\)个,那每个物品最多只会出现\(k\)次,多余的丢掉,剩下的总数如果大于等于\(3k\)则true。最后输出答案时也是小小技巧吧,用\({1,1+k,1+2k}\)组成一组,因为多于\(k\)个的都删了所以这三个一定不同。
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std; const int maxn = 1e5 + 5;
int n, a[maxn];
vector<int> v, x; bool ok(int mid) {
int cnt = 1;
x.clear();
for (int i = 1; i <= n; i++) {
if (a[i] == a[i - 1]) {
cnt++;
if (cnt <= mid) x.push_back(a[i]);
} else {
cnt = 1;
x.push_back(a[i]);
}
}
if (x.size() < 3 * mid) return false;
return true;
} int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
sort(a + 1, a + 1 + n); int l = 0, r = n / 3, ans;
while (l <= r) {
int mid = (l + r) >> 1;
if (ok(mid)) {
l = mid + 1;
ans = mid;
v = x;
} else r = mid - 1;
} printf("%d\n", ans);
for (int i = 0; i < ans; i++) {
printf("%d %d %d\n", v[i + ans * 2], v[i + ans], v[i]);
}
}

Codeforces 140C(二分、构造)的更多相关文章

  1. 【Atcoder】AGC 020 D - Min Max Repetition 二分+构造

    [题意]定义f(A,B)为一个字符串,满足: 1.长度为A+B,含有A个‘A',B个'B'. 2.最长的相同字符子串最短. 3.在满足以上2条的情况下,字典序最小. 例如, f(2,3) = BABA ...

  2. codeforces 1041 e 构造

    Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...

  3. Codeforces Round #534 (Div. 2)D. Game with modulo-1104-D(交互+二分+构造)

    D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #608 (Div. 2) E. Common Number (二分,构造)

    题意:对于一个数\(x\),有函数\(f(x)\),如果它是偶数,则\(x/=2\),否则\(x-=1\),不断重复这个过程,直到\(x-1\),我们记\(x\)到\(1\)的这个过程为\(path( ...

  5. CodeForces - 363D --二分和贪心

    题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...

  6. Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论

    n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...

  7. Codeforces - 474D - Flowers - 构造 - 简单dp

    https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...

  8. luogu CF125E MST Company wqs二分 构造

    LINK:CF125E MST Company 难点在于构造 前面说到了求最小值 可以二分出斜率k然后进行\(Kruskal\) 然后可以得到最小值.\(mx\)为值域. 得到最小值之后还有一个构造问 ...

  9. Codeforces Global Round 8 B. Codeforces Subsequences(构造)

    题目链接:https://codeforces.com/contest/1368/problem/B 题意 构造最短的至少含有 $k$ 个 $codeforces$ 子序列的字符串. 题解 如下表: ...

随机推荐

  1. tkinter之button

    Button按钮,直接上代码: from tkinter import * def gs(): global read s=Label(read,text='昨夜西风凋敝树,堵上高楼,望尽天涯路!', ...

  2. deep QA 基于生成的chatbot系统

    deep QA: https://github.com/Conchylicultor/DeepQA  基于论文:https://arxiv.org/pdf/1506.05869.pdf  基于生成的c ...

  3. CodeForces 547E:Mike and Friends(AC自动机+DFS序+主席树)

    What-The-Fatherland is a strange country! All phone numbers there are strings consisting of lowercas ...

  4. nginx版本策略

    近期Nginx发布了1.17.0主线版本与1.16.0稳定版本,并且发布了一篇文章< Introducing NGINX 1.16 and 1.17 >说明Nginx的版本更新策略.推荐分 ...

  5. 【Lintcode】003.Digit Counts

    题目: Count the number of k's between 0 and n. k can be 0 - 9. Example if n = 12, k = 1 in [0, 1, 2, 3 ...

  6. unicode和utf-8互转

    1.1 ASCII码 我们知道, 在计算机内部, 所有的信息最终都表示为一个二进制的字符串. 每一个二进制位(bit)有0和1两种状态, 因此八个二进制位就可以组合出 256种状态, 这被称为一个字节 ...

  7. bzoj 1004 Cards & poj 2409 Let it Bead —— 置换群

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 关于置换群:https://www.cnblogs.com/nietzsche-oie ...

  8. C# Linq 取得两个列表的交集

    我们经常会用到linq 来查询 一个数组中和另一个数组中相同的项, 这个时候就会用到IEqualityComparer接口. public class StudyInfoModel {      pu ...

  9. 云-资讯-Micron-Insight:云的形成方式 — 以及它的发展方向

    ylbtech-云-资讯-Micron-Insight:云的形成方式 — 以及它的发展方向 1.返回顶部 1. 云的形成方式 — 以及它的发展方向 当你坐下来开始一天工作的时候,你可能不会考虑到你所做 ...

  10. UE4 框架

    转自:http://www.cnblogs.com/NEOCSL/p/4059841.html 有很多人是从UE3 接触到Unreal,如果你也对UE3非常了解,便能很快的上手UE4.但是,UE4的开 ...