B. Sereja and Stairs
来源:互联网 发布:linux根文件系统详解 编辑:程序博客网 时间:2024/06/05 09:12
解题说明:此题要求找出凸型数列,也就是中间数大于前后数的情况或者中间数大于后数的情况。先把输入的序列按从小到大排序,然后依次挑出不相同的数(顺挑)。接着倒序再挑出不相同的数(可以与顺挑时的数相同)。有一个要注意的地方是,挑出的那些数的位置需要标记下,防止逆挑的时候重复挑。
#include<iostream>#include<cstdio>#include<cmath>#include<cstdlib>#include <algorithm>using namespace std;int main() {int n, a[100000], b[5001] = { 0 }, i, j, max = 0, c[100000], k, count = 0;scanf("%d", &n);for (i = 0; i<n; i++){scanf("%d", &a[i]);b[a[i]]++;if (a[i] >= max){max = a[i];}}j = 0;for (i = 0; i<max; i++){if (b[i]>0){count++;c[j++] = i;b[i]--;}}count++;c[j++] = max;for (i = max - 1; i>0; i--){if (b[i]>0){count++;c[j++] = i;b[i]--;}}printf("%d\n", count);for (i = 0; i<j; i++){printf("%d ", c[i]);}printf("\n");return 0;}
0 0
- B. Sereja and Stairs
- 381-B. Sereja and Stairs
- Sereja and Stairs
- Sereja and Stairs
- codeforces--2014/1/13--B. Sereja and Stairs
- Codeforces Round #223 (Div. 2) B. Sereja and Stairs
- Codeforces 381B 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
- CF223B题Sereja and Stairs
- B. Sereja and Array
- B. Sereja and Suffixes
- B. Sereja and Contests
- B. Sereja and Contests
- B. Sereja and Mirroring
- B. Sereja and Mirroring
- Codeforces Round #223 (Div. 2)——B. Sereja and Stairs
- coderforce --B. Sereja and Suffixes
- Emmet高效开发web前端代码
- 快乐一。点。吧,极品笑话!!
- linux 和 android 默认支持的部分 usb 网卡芯片
- 感觉用路由器上网变慢怎么办
- HTML 笔记
- B. Sereja and Stairs
- Java 数据库连接字符串
- centos设置静态IP
- cocos2dx之CCActionEase,CCEaseExponentialIn等变速Action
- 安卓开发-Activity中finish() onDestroy() 和System.exit()的区别
- 用DiskGenius恢复误删除或误格式化后的文件
- C语言指针
- 查询表涉及到的存储过程名
- C语言文件操作函数大全