Codeforces Round #223 (Div. 2) B. Sereja and Stairs【模拟】
来源:互联网 发布:mac版spss使用教程 编辑:程序博客网 时间:2024/05/22 04:50
题意:已知n个数,要求构成一个数列,使得构成数列中一个数最大 ,往两边依次严格递减 , 问这个数列最长多长并且输出该数列。
思路:最大的放中间,第二大的往两边放,以此类推。 实现过程:用map来计数,计数完成后复制给struct。这样的好处是可以节约很多不必要的空间消耗。然后开一个数组来模拟第一句话的思路。用left,right标记左边和右边的下标。
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=1e5+50;int ans[3*maxn];map <int,int> mp;struct node{ int v,cnt;}d[maxn];int main(void){ int m; cin >> m; for(int i=1;i<=m;i++) { int x; scanf("%d",&x); mp[x]++; } int cnt=1; for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++) d[cnt].v=it->first, d[cnt].cnt=it->second,cnt++; //for(int i=1;i<cnt;i++) // printf("%d %d\n",d[i].v,d[i].cnt); int index=150000,left=150000,right=150000; ans[index]=d[cnt-1].v; left--,right++; for(int i=cnt-2;i>=1;i--) { if(d[i].cnt==1) ans[left--]=d[i].v; else if(d[i].cnt >=2) ans[left--]=ans[right++]=d[i].v; } printf("%d\n",(right-1)-(left+1)+1); for(int i=left+1;i<=right-1;i++) printf("%d ",ans[i]); printf("\n");}
阅读全文
0 0
- 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 Round #223 (Div. 2)——B. Sereja and Stairs
- Codeforces Round #215 (Div. 2) -B. Sereja and Suffixes
- Codeforces Round #215 (Div. 2) -B. Sereja and Suffixes
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes
- Codeforces Round #235 (Div. 2)B. Sereja and Contests
- Codeforces Round #187 (Div. 2) B. Sereja and Array
- CodeForces Round 223 Div 2 C Sereja and Prefixes
- Codeforces Round #223 (Div. 2)--A. Sereja and Dima
- Codeforces Round #223 (Div. 2) E Sereja and Brackets
- Codeforces Round #223 (Div. 2)-C. Sereja and Prefixes
- Codeforces Round #243 (Div. 1) B Sereja and Table
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 题解
- B. Sereja and Stairs
- Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)
- Codeforces Round #395(Div. 2)B. Timofey and cubes【模拟】
- 深度学习调参
- CXF客户端设置连接超时时间
- 最长单增子序列
- 逆向实战之入门去除baldbooth广告
- [Leetcode] 347. Top K Frequent Elements 解题报告
- Codeforces Round #223 (Div. 2) B. Sereja and Stairs【模拟】
- 问题 : 最小的K个数
- Python进阶之路——六
- 深入分析JavaWeb技术内幕笔记(知识补充)
- 二分查找 java递归和非递归实现
- linux使用scp进行2台服务器内网文件传输
- mysql 取一条离当前时间最近的记录
- myBatis的Dao开发(4)
- 数组类的常用的几种方法