Codeforces 381B Sereja and Stairs(水题)
来源:互联网 发布:仟游软件科技 编辑:程序博客网 时间:2024/06/16 18:12
题目链接: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;}
0 0
- Codeforces 381B Sereja and Stairs(水题)
- 381-B. Sereja and Stairs
- B. Sereja and Stairs
- codeforces--2014/1/13--B. Sereja and Stairs
- Codeforces Round #223 (Div. 2) B. Sereja and Stairs
- Codeforces Round #223 (Div. 2) B. Sereja and Stairs【模拟】
- Codeforces Round #223 (Div. 2)A. Sereja and Dima&&B. Sereja and Stairs
- Codeforces 401B Sereja and Contests(水题)
- Codeforces 368B:Sereja and Suffixes(水题)
- Codeforces 401B Sereja and Contests【水题】
- Codeforces Round #223 (Div. 2)——B. Sereja and Stairs
- codeforces B. Sereja and Contests
- Sereja and Stairs
- Sereja and Stairs
- Codeforces 426 B Sereja and Mirroring【暴力枚举+模拟】水题
- Codeforces 380B Sereja and Tree(暴力)
- CodeForces - 368B Sereja and Suffixes (map)
- CodeForces 314 B.Sereja and Periods(dp)
- project、target的build settings、info信息剖析
- 2014开年文章
- poj-1947-Rebuilding Roads
- iOS中事件响应的学习记录
- ZOJ 2770 Burn the Linked Camp 差分约束系统
- Codeforces 381B Sereja and Stairs(水题)
- Qt树形控件QTreeView使用1——节点的添加删除操作
- "Not a bug" VS "Won't Fix"
- ASP.NET内置对象之Session ,Cookie ,Application
- 使用fedup本地升级Fedora 19至 Fedora 20报错
- huyjnga
- rman backup database 报 RMAN-06169
- 选中Cell后,让阴影部分消失,即去掉选中状态
- zookeeper客户端和服务端交互分析