题目描述

Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 1 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 3 3 steps, and the second contains 4 4 4 steps, she will pronounce the numbers 1,2,3,1,2,3,4 1, 2, 3, 1, 2, 3, 4 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.

输入输出格式

输入格式:

The first line contains n n n ( 1≤n≤1000 1 \le n \le 1000 1≤n≤1000 ) — the total number of numbers pronounced by Tanya.

The second line contains integers a1,a2,…,an a_1, a_2, \dots, a_n a1​,a2​,…,an​ ( 1≤ai≤1000 1 \le a_i \le 1000 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 x x steps, she will pronounce the numbers 1,2,…,x 1, 2, \dots, x 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.

输出格式:

In the first line, output t t t — the number of stairways that Tanya climbed. In the second line, output t t t numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.

输入输出样例

输入样例#1: 复制

7
1 2 3 1 2 3 4

输出样例#1: 复制

2
3 4 

输入样例#2: 复制

4
1 1 1 1

输出样例#2: 复制

4
1 1 1 1 

输入样例#3: 复制

5
1 2 3 4 5

输出样例#3: 复制

1
5 

输入样例#4: 复制

5
1 2 1 2 1

输出样例#4: 复制

3
2 2 1 

很简单,上代码:

#include<cstdio>
using namespace std;
int a[1000],b[1000];
int n,temp,j=0,ans=0;
int main()
{scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&temp);a[temp]++;if(temp!=1){b[j]++;}if(temp==1)j++;}printf("%d\n",a[1]);for(int i=1;i<=j;i++)printf("%d ",(b[i]+1));return 0;}

CF1005A Tanya and Stairways相关推荐

  1. CodeForces - 1005A . Tanya and Stairways

    题目链接 A. Tanya and Stairways time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. 婚礼请帖_第一次在线婚礼发生在1876年

    婚礼请帖 重点(Top highlight) As the Covid-19 pandemic wears on, more and more of life has moved online - s ...

  3. 基础算法 —— 模拟思维

    [概述] 模拟,是根据实际问题建立模型,模拟实际按程序走一遍,最终求出答案. 思维,则是与逻辑思维有关,其需要针对题意.数据范围等抽丝剥茧抽离出有用的信息,从而得出一个结果. 对于一般的模拟,直接根据 ...

  4. Codeforces Round #496 (Div. 3)【未完结】

    2022.3.5 题目地址:https://codeforces.com/contest/1005 目录 A. Tanya and Stairways[找规律] B. Delete from the ...

  5. Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂

    B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...

  6. 940B. Our Tanya is Crying Out Loud

    B. Our Tanya is Crying Out Loud:题目 1特判,因为除1还是本身,这点就很淦 #include <bits/stdc++.h> using namespace ...

  7. Tanya出了新碟,这让我想起来了高中时听她的记念

    專輯『雙棲動物』中,Tanya獨具魅力的創作與聲線依然穿透人心,音樂風格趨向一致,整張專輯的概念都會情歌氣味鮮明,勢必再度跳脫一般市場作品,成為優質情歌指標. 整張專輯的音樂架構以Tanya的創作出發 ...

  8. CF508D Tanya and Password(欧拉回路)

    解析 之前模拟考过的一道题 把字符串当成前后缀之间的连边即可 注意即使图的度数符合要求,也可能由于不连通而无解,需要再特判一下 #include<bits/stdc++.h> using ...

  9. Codeforces Round #324 (Div. 2) B. Kolya and Tanya

    思路:因为题目说只要存在组ai?+?ai?+?n?+?ai?+?2n?≠?6就令人满意,也就是不满意的情况就是所有ai?+?ai?+?n?+?ai?+?2n?都等于6 那就用所有的情况减去不满意的情况 ...

最新文章

  1. 中山大学计算机学院运动会,中山大学2019年运动会.PDF
  2. POJ 3358 Period of an Infinite Binary Expansion ★ (数论好题:欧拉函数)
  3. 【HIMI转载推荐之三】新手教程之如何向APP STORE提交应用
  4. 互联网女皇”Mary Meeker 2015互联网趋势报告说了些什么
  5. ICCV 2019 《Robust Change Captioning》论文笔记(数据集)
  6. BZOJ2131免费的馅饼 DP+树状数组
  7. windows文件路径大于MAX_PATH
  8. Spring 学习教程(一): 认识 Spring 框架
  9. MyEclipse中代码提醒功能
  10. 1-AII--BroadcastReceiver广播的静态注册与动态注册
  11. Activiti 用户任务并行动态多实例(多用户执行流程)
  12. 试试既然没人玩,没得试验了
  13. tomcat ajp协议安全限制绕过漏洞_Apache tomcat 文件包含漏洞复现(CVE20201938)
  14. python虚拟环境搭建mac_在MAC上安装Python虚拟环境
  15. 【C语言】16-预处理指令2-条件编译
  16. 对于自己(Android)秋招的一点总结(感慨)
  17. ps小技巧(复制选区)
  18. 浅谈工程总承包项目WBS的重要性与创建方法
  19. 深圳赏给我的耳光:说到底,生活就是一场接着一场的较量
  20. 王者荣耀赛季更新服务器维护到什么时候,王者荣耀赛季更新到几点?s24维护公告最新内容一览[多图]...

热门文章

  1. MySQL事务的四种隔离界别以及会造成的问题和解决办法
  2. C++ Primer Plus 阅读笔记一
  3. 【VBA编程】认识VBA、VBE,一个小实验和帮助的使用方法
  4. K-Means(K-均值)、k-median聚类算法机器学习
  5. 德州扑克比牌、认牌功能实现作业
  6. 视窗(Windows 7)模块化是什么意思?
  7. java和web哪个难_web前端和java哪个难学?哪个简单?
  8. 人生没有太晚的开始,只有不开始
  9. Linux平台常用终端指令合集【超级全】
  10. 打印一只Nyan Cat(彩虹猫)(C++)3.0[多色版]