ACM集训
2019-07-18
09:06:10
emmm....
昨天5个小时做了一道题,心情复杂,不着急慢慢来
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The ii-th page contains some mystery that will be explained on page aiai (ai≥iai≥i).
Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page ii such that Ivan already has read it, but hasn't read page aiai). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
The first line contains single integer nn (1≤n≤1041≤n≤104) — the number of pages in the book.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (i≤ai≤ni≤ai≤n), where aiai is the number of page which contains the explanation of the mystery on page ii.
Print one integer — the number of days it will take to read the whole book.
9
1 3 3 6 7 6 8 8 9
4
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number 22 and 33. During the third day — pages 44-88. During the fourth (and the last) day Ivan will read remaining page number 99.
题解:
这道题比较好过,但是看题有点艰难
代码:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std; ll a[]={};
int main()
{
ll n;
ll i;
scanf("%lld",&n);
for(i = ; i <= n; i++)
{
scanf("%lld", &a[i]);
}
ll day = ;
ll min = ;
ll max = ;
for(i = ; i <= n; i++)
{
min = i;
if(a[i] > max)
{
max = a[i];
}
if(min == max)
{
day++;
}
}
cout << day << endl; return ;
}
题2 一言难尽
Your task is to implement a decoder of the famous Morse alphabet. As most of you know,
the Morse code represents characters as variable-length sequences of short and long signals
(“beeps”), often written as dots and dashes. For those who do not remember their scouting
years, the following table shows the Morse code sequences for all letters:
A .- E . I .. M -- Q --.- U ..- Y -.--
B -... F ..-. J .--- N -. R .-. V ...- Z --..
C -.-. G --. K -.- O --- S ... W .--
D -.. H .... L .-.. P .--. T - X -..-
If more letters are to be transferred, they are separated by a short pause, typically written as
a slash. A space between words is represented by an even longer pause, written as two slashes
The input contains several test cases. Each test case is specified on one line with at most 1000
characters, which describes a valid Morse code transmission. Specifically:
• The line consists only of dashes (“-”), dots (“.”), and slashes (“/”).
• There is at least one character.
• The first and last characters will never be a slash.
• There will never be more than two slashes together.
• Each non-empty sequence between two slashes contains a valid Morse code of one letter.
For each test case, print one line containing the decoded message in uppercase letters.
.-/-.-./--
-.-./-/..-//---/.--././-.
./-/-././-/./.-./.-//-.../.-././...-/../-/-.--//-.-./..../.-/.-../.-.././-./--./.
ACM
CTU OPEN
ETNETERA BREVITY CHALLENGE 代码:
问题一:
我把K的赋值弄错了,欸……
字符串的比较,我应该用 a[i] == s1.substr(p,lenth);但我用的一种错误的赋值导致接下来的种种,不过这道题确实锻炼了我写代码能力,我第一遍的代码140多行,难受想哭
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a[];
a[] = ".-";
a[] = "-...";
a[] = "-.-.";
a[] = "-.."; a[] = ".";
a[] = "..-.";
a[] = "--.";
a[] = "...."; a[] = "..";
a[] = ".---";
a[] = "-.-";
a[] = ".-.."; a[] = "--";
a[] = "-.";
a[] = "---";
a[] = ".--."; a[] = "--.-";
a[] = ".-.";
a[] = "...";
a[] = "-"; a[] = "..-";
a[] = "...-";
a[] = ".--";
a[] = "-..-"; a[] = "-.--";
a[] = "--..";
string s1;
while(cin >> s1)
{
int p = ;
int count = ;
for(int i = ; i < s1.length(); i++)
{
if(s1[i] != '/')
{
count++;
if(i == s1.length() - )
{
int sp = ;
for(int j = ; j <= ; j++)
{
if(a[j] == s1.substr(p,count))
{
printf("%c", + j - );
sp = ;
break;
}
}
if(sp == )
{
cout << endl;
break;
}
}
}
if(s1[i] == '/')
{
for(int j = ; j <= ; j++)
{ if(a[j] == s1.substr(p,count))
{
printf("%c", + j - );
p = i+;
count = ;
break;
}
}
if(s1[i+] == '/')
{
cout << " " ;
i++;
p++;
}
}
}
}
}
Your task is to implement a decoder of the famous Morse alphabet. As most of you know,
the Morse code represents characters as variable-length sequences of short and long signals
(“beeps”), often written as dots and dashes. For those who do not remember their scouting
years, the following table shows the Morse code sequences for all letters:
A .- E . I .. M -- Q --.- U ..- Y -.--
B -... F ..-. J .--- N -. R .-. V ...- Z --..
C -.-. G --. K -.- O --- S ... W .--
D -.. H .... L .-.. P .--. T - X -..-
If more letters are to be transferred, they are separated by a short pause, typically written as
a slash. A space between words is represented by an even longer pause, written as two slashes
ACM集训的更多相关文章
- yzm10的ACM集训小感
7月30号,ACM集训进行了两周,一切都已on the right way.这时的我适时地从题海中探出头,其实除了刷题,也该写点什么来总结下过去.首先,在第一周里,我学习了数据结构,知道了STL这么一 ...
- ACM集训的Day3 B。。。盲目搜索之DFS。。。
milk 一.题目描述: gzp有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满牛奶的.有时,农民把牛奶从一个桶倒到 另一个桶中,直到被灌 ...
- ACM集训的1B。。。。黑色星期五。。。。2333333
题目: 印象中有好多个13号是星期五,13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数.给出N年的一个周期,要求计算1900年1月1日至1900 ...
- ACM集训的Training Day 3的A题。。。
A. 等差数列 一.题目描述: 一个等差数列是一个能表示成a, a+b, a+2b,..., a+nb (n=0,1,2,3,...)的数列. 在这个问题中a是一个非负的整数,b是正整数.写一个程序来 ...
- ACM集训的第。。。诶~不知道第几题=.=
题目: 郭铮鹏认为排序是一种很频繁的计算任务,所以他考虑了一个简单的问题:现在最多只有三值的排序问题.一个实际的例子是,当我们给某项竞赛的优胜者按金银铜牌排序的时候.在这个任务中可能的值只有三种1,2 ...
- ACM集训的第一题
对于一群NP(2<=NP<=10)个要互送礼物的朋友,郭铮鹏要确定每个人送出的钱比收到的多多少. 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人 ...
- 除法(Division ,UVA 725)-ACM集训
参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html 算法学到很弱,连这么简单个问题都难到我了.但我偏不信这个邪,终于做出来了.不过,是参照别人的 ...
- 矩形嵌套问题-ACM集训
参考 http://blog.csdn.net/xujinsmile/article/details/7861412 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可以嵌套在矩形 ...
- ACM集训日志——day1——15.7.8
UVA 11292 The Dragon of Loowater 题意 给n个头,m个骑士,骑士有能力值x,代表他可以砍掉一个直径不超过x的头,并且佣金为x,求要砍掉所有的头,需要的最少佣金是多少. ...
随机推荐
- 小福bbs-冲刺日志(第六天)
[小福bbs-冲刺日志(第六天)] 这个作业属于哪个课程 班级链接 这个作业要求在哪里 作业要求的链接 团队名称 小福bbs 这个作业的目标 后端努力完成大部分功能操作,前端UI完成大部分功能测试 作 ...
- 10分钟彻底理解Redis持久化和主从复制
在这篇文章,我们一起了解 Redis 使用中非常重要的两个机制:Reids 持久化和主从复制. 什么是 Redis 持久化? Redis 作为一个键值对内存数据库(NoSQL),数据都存储在内存当中, ...
- openwrt共享打印机需要安装哪几个文件
opkg updateopkg install luci-app-p910ndopkg install kmod-usb-printer
- 《Linux性能及调优指南》 Linux进程管理
版权所有: 原文名称:<Linux Performance and Tuning Guidelines> 原文地址:http://www.redbooks.ibm.com/abstract ...
- 【转】自动化框架中引入ExtentReport美化报告
本文链接:https://blog.csdn.net/qq_30353203/article/details/82023922一.先引入三个依赖包 <dependency> <gro ...
- CentOS上安装GlassFish4.0
1. 安装jdk 2. 下载并安装glassfish4 [root@linuxidc ~]# mv glassfish-4.0-ml.zip /usr/share/glassfish-4.0-ml. ...
- 如何在shell脚本中获取当前用户名?
答:使用环境变量USER即可 如在脚本中打印当前用户名; #!/bin/sh echo "user name = ${USER}"
- shell按月循环取数
这里有个需求,按月查询,并且要输出每月的开始日期,结束日期. shell脚本如下: #!/bin/sh echo "0个参数时, 按月执行,默认当前月份 " echo " ...
- osgViewer
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source ...
- Spring5源码分析之启动类的相关接口和注解
一些基础但是核心的知识总结: Spring Boot项目启动的时候需要加@Configuration. @ComponentScan @Configuration + @Bean 把第三方jar包注入 ...