题目链接:Codeforces 381B Sereja and Stairs
题目大意:给出若干个数,要求从中挑选出尽量多的数字组成一个先递增,后递减的序列。
解题思路:因为每个数字最大5000,所以开一个数组记录下每个数字出现过的次数,然后正的遍历一次,反着遍历一次即可。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 5005;
int n, c[N], t[N*2], cnt;
void init () {
cnt = 0;
memset(c, 0, sizeof(c));
int a;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
c[a]++;
}
}
void solve () {
int tmp = 0;
for (int i = 0; i < N; i++) if (c[i]) {
t[cnt++] = i;
tmp = max(tmp, i);
c[i]--;
}
for (int i = tmp - 1; i >= 0; i--) if (c[i]) {
t[cnt++] = i;
}
printf("%d\n%d", cnt, t[0]);
for (int i = 1; i < cnt; i++) printf(" %d", t[i]);
printf("\n");
}
int main () {
init();
solve();
return 0;
}
分享到:
相关推荐
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 1105B - Zuhair and Strings 测试点37个(全)
Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B.
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
暴枚最长桌脚的长度$l$,然后长度比$l$长的桌脚全部都要砍掉长度比$l$短的桌脚选择代价前$k$小的砍掉用线段树维护;示例程序 :typedef long l
Codeforces 题库 201-294 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces编程网站预测分数插件
codeforces算法比赛题:1295A题
python-for-codeforces一些使用python刷codeforces题的源码
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
codeforces每日一题。 题意: 给出一个数组,让你挑选出能组成任意pair差值为2的幂的序列,并且使这个序列长度尽可能大。 思路: 针对于挑选出来的序列,任意pair对的差值为2的幂数。 假设有多个pair对,设dis(a,b)=2...
Codeforces 185A - Plant 全测试点49个
这个道题单独来看是不难,变成交互题就难了,对于交互题不理解的可以参考这篇博客:点击这里 操作就是一个删除叶子节点的过程。 AC代码: const int N = 1010; int n; int u, v, x; set g[N]; int ans[N]; int main...
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
2020.4.2更新:偶然发现luogu有题单功能了 更好的阅读体验 Problems Math Greedy DP : : : Graph 最短路: 分层最短路: 并查集: 带权并查集: 二分图: 最小生成树: Tree 单调栈: 单调队列: 树链剖分: with...
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
Some of the Codeforces problems codes
题目分析:因为最多只能求 n/2 次lca,每次需要两个节点作为参数,也就是说每个点我们至多遍历一遍,读完题后没什么思路,队友给我提示说可以参考树上启发式合并的思想,从叶子结点向上不断合并找到根节点,由此我...