CF 1005A Tanya and Stairways 【STL】
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1,2,3,1,2,3,4.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input
The first line contains n (1≤n≤1000) — the total number of numbers pronounced by Tanya.
The second line contains integers a1,a2,…,an (1≤ai≤1000) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1,2,…,x in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output
In the first line, output t — the number of stairways that Tanya climbed. In the second line, output t numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Examples
Input
7
1 2 3 1 2 3 4
Output
2
3 4
Input
4
1 1 1 1
Output
4
1 1 1 1
Input
5
1 2 3 4 5
Output
1
5
Input
5
1 2 1 2 1
Output
3
2 2 1
//xjb模拟
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define rep(i,x,n) for(int i=(x); i<(n); i++)
#define in freopen("in.in","r",stdin)
#define out freopen("out.out","w",stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const ll LNF = 1e18;
const int N = 1e5 + 20;
const int maxm = 1e6 + 10;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int dx[] = {-1,1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n,a[N];
set<int> s;
vector<int> v;
int main()
{
while(~scanf("%d",&n))
{
s.clear();
v.clear();
rep(i,0,n)
{
scanf("%d",&a[i]);
if(a[i]==1 && i!=0)
{
v.push_back(a[i-1]);
}
s.insert(a[i]);
}
if(s.size() == 1) //复杂的特判
{
printf("%d\n",n);
rep(i,0,n)
{
if(i!=n-1) printf("%d ",a[i]);
else printf("%d\n",a[i]);
}
}
else if(s.size() == n) //复杂的特判
{
printf("1\n");
printf("%d\n",a[n-1]);
}
else
{
printf("%d\n",v.size()+1);
rep(i,0,v.size())
{
printf("%d ",v[i]);
}
printf("%d\n",a[n-1]);
}
}
}
/*
1234 12345 1234567
*/
【非STL-数组】
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a[1010],b[1010],ans=1;
cin>>n>>a[0];
for(int i=1;i<n;i++)
{
cin>>a[i];
if(a[i]==1)
b[ans++]=a[i-1];
}
cout<<ans<<endl;
b[ans++]=a[n-1];
for(int i=1;i<ans;i++)
cout<<b[i]<<" ";
return 0;
}
CF 1005A Tanya and Stairways 【STL】的更多相关文章
- 【最短路】【STL】CSU 1808 地铁 (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1808 题目大意: N个点M条无向边(N,M<=105),每条边属于某一条地铁Ci ...
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn
题目链接: http://codeforces.com/problemset/problem/696/A 题目大意: 一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边 ...
- 蓝桥 ADV-233 算法提高 队列操作 【STL】
算法提高 队列操作 时间限制:1.0s 内存限制:256.0MB 问题描述 队列操作题.根据输入的操作命令,操作队列(1)入队.(2)出队并输出.(3)计算队中元素个数并输出. ...
- CF 1006B Polycarp's Practice【贪心】
Polycarp is practicing his problem solving skill. He has a list of n problems with difficulties a1,a ...
- CF987A Infinity Gauntlet【STL】
[链接]:CF987A [分析]:运用map [代码]: #include <iostream> #include<queue> #include<string.h> ...
- 华农oj Problem B: Averyboy找密码【STL】
Problem B: Averyboy找密码 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 83 Solved: 29 [Submit][Status] ...
- 洛谷P1118 数字三角形【dfs】【STL】
题目链接:https://www.luogu.org/problemnew/show/P1118 题意: 1~n的一个排列,相邻的两项加起来得到下一行. 现在给定最后一行的数字,问最初的1~n的排列是 ...
- 【STL】优先队列priority_queue详解+OpenJudge-4980拯救行动
一.关于优先队列 队列(queue)这种东西广大OIer应该都不陌生,或者说,队列都不会你还学个卵啊(╯‵□′)╯︵┻━┻咳咳,通俗讲,队列是一种只允许从前端(队头)删除元素.从后端(队尾)插入元素的 ...
随机推荐
- Div+Css中transparent制作奥运五环
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [bzoj5285] [HNOI2018]寻宝游戏
Description 某大学每年都会有一次Mystery Hunt的活动,玩家需要根据设置的线索解谜,找到宝藏的位置,前一年获胜的队伍可以获得这一年出题的机会. 作为新生的你,对这个活动非常感兴趣. ...
- mysql5.7 MRG集群部署学习
文章目录 1.安装mysql 2.修改配置文件: 3.安装group_replicatin插件,启动group_replication 4.添加节点node-02 node-03: 有关复制组的相关原 ...
- 雪碧图background-position的rem用法
background的雪碧图配合rem就正常写即可,要加上background-size,大小为sprites的原图尺寸,宽高为一帧的尺寸.例如: .player{ width: 2.32rem; / ...
- API网关Kong部署和使用文档
KONG安装使用说明 系统版本:ubuntu14 1.下载安装包 $ wget https://github.com/Mashape/kong/releases/download/0.8.3/kong ...
- 洛谷P2568 GCD (欧拉函数/莫比乌斯反演)
P2568 GCD 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入输出格式 输入格式: 一个整数N 输出格式: 答案 输入输出样例 输入 ...
- wyh的天鹅~vector的使用
链接:https://www.nowcoder.com/acm/contest/93/L来源:牛客网 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 262144K,其他语言52428 ...
- bzoj 4836 [Lydsy1704月赛]二元运算 分治FFT+生成函数
[Lydsy1704月赛]二元运算 Time Limit: 8 Sec Memory Limit: 128 MBSubmit: 577 Solved: 201[Submit][Status][Di ...
- domReady的兼容性实现方法
一.为何要实现domReay方法? 举例: <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- mpvue基本使用
## 什么是mpvue ## - 美团开发使用vue语法开发小程序的前端框架 - 适用于vue语法开发 - 会调用部分小程序API ## 创建mpvue项目 ## 1. 必须安装node.js 2. ...