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.

Input
9
1 3 3 6 7 6 8 8 9
Output
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集训的更多相关文章

  1. yzm10的ACM集训小感

    7月30号,ACM集训进行了两周,一切都已on the right way.这时的我适时地从题海中探出头,其实除了刷题,也该写点什么来总结下过去.首先,在第一周里,我学习了数据结构,知道了STL这么一 ...

  2. ACM集训的Day3 B。。。盲目搜索之DFS。。。

    milk 一.题目描述: gzp有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满牛奶的.有时,农民把牛奶从一个桶倒到 另一个桶中,直到被灌 ...

  3. ACM集训的1B。。。。黑色星期五。。。。2333333

    题目: 印象中有好多个13号是星期五,13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数.给出N年的一个周期,要求计算1900年1月1日至1900 ...

  4. ACM集训的Training Day 3的A题。。。

    A. 等差数列 一.题目描述: 一个等差数列是一个能表示成a, a+b, a+2b,..., a+nb (n=0,1,2,3,...)的数列. 在这个问题中a是一个非负的整数,b是正整数.写一个程序来 ...

  5. ACM集训的第。。。诶~不知道第几题=.=

    题目: 郭铮鹏认为排序是一种很频繁的计算任务,所以他考虑了一个简单的问题:现在最多只有三值的排序问题.一个实际的例子是,当我们给某项竞赛的优胜者按金银铜牌排序的时候.在这个任务中可能的值只有三种1,2 ...

  6. ACM集训的第一题

    对于一群NP(2<=NP<=10)个要互送礼物的朋友,郭铮鹏要确定每个人送出的钱比收到的多多少. 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人 ...

  7. 除法(Division ,UVA 725)-ACM集训

    参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html 算法学到很弱,连这么简单个问题都难到我了.但我偏不信这个邪,终于做出来了.不过,是参照别人的 ...

  8. 矩形嵌套问题-ACM集训

    参考 http://blog.csdn.net/xujinsmile/article/details/7861412 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可以嵌套在矩形 ...

  9. ACM集训日志——day1——15.7.8

    UVA 11292 The Dragon of Loowater 题意 给n个头,m个骑士,骑士有能力值x,代表他可以砍掉一个直径不超过x的头,并且佣金为x,求要砍掉所有的头,需要的最少佣金是多少. ...

随机推荐

  1. docker gitlab and gitlab api

    https://docs.gitlab.com/ee/api/repositories.html curl --header "PRIVATE-TOKEN: fxhDXPRJAowCouXE ...

  2. make 实例 二 V56

    ######################################################################### # # Makefile used for buil ...

  3. Enhancer | 增强子 专题

    要做就做深做精! Everything needs good justification. The interpretation should be biologically and statisti ...

  4. Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'kindergarten.n.stuMChkTime' which is not functionally dependent on columns in GROUP BY clause; this is in

    错误原因: ​ sql _mode中only _full _group _by不兼容的问题 解决思路: ​ 既然是only _full _group _by不兼容,那就把它去掉就好啦 show var ...

  5. Excel 如何自动调整列宽?

      excel如何自动调整列宽 1.打开Excel表格,选中要调整的表格. 2.点击"格式",选择"自动调整列宽",右键点击"设置单元格格式" ...

  6. Navicat Premium 12 mysql show error: connection is being used

    错误原因:连接数满了. 解决方案:杀掉无用连接,释放资源.

  7. Python的collections之defaultdict的使用及其优势

    user_dict = {} users = ["baoshan1", "baoshan2", "baoshan3","baosh ...

  8. 【Redis】Redis Sentinel 哨兵模式搭建

    Redis Sentinel介绍 Redis Sentinel是Redis的官方高可用性解决方案 Redis Sentinel为Redis提供高可用性.实际上,这意味着使用Sentinel可以创建一个 ...

  9. attribute__关键字举例之visibility

    /** @file visibilityT.c * @note * @brief * @author * @date 2019-6-20 * @note v1.0.0 Created * @histo ...

  10. 解决no module named setuptools

    To install setuptools on Debian: sudo apt-get install python-setuptools For Python 3.x: sudo apt-get ...