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[100005]={0}; int main() { ll n; ll i; scanf("%lld",&n); for(i = 1; i <= n; i++) { scanf("%lld", &a[i]); } ll day = 0; ll min = 0; ll max = 1; for(i = 1; i <= n; i++) { min = i; if(a[i] > max) { max = a[i]; } if(min == max) { day++; } } cout << day << endl; return 0; }
题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[100]; a[1] = ".-"; a[2] = "-..."; a[3] = "-.-."; a[4] = "-.."; a[5] = "."; a[6] = "..-."; a[7] = "--."; a[8] = "...."; a[9] = ".."; a[10] = ".---"; a[11] = "-.-"; a[12] = ".-.."; a[13] = "--"; a[14] = "-."; a[15] = "---"; a[16] = ".--."; a[17] = "--.-"; a[18] = ".-."; a[19] = "..."; a[20] = "-"; a[21] = "..-"; a[22] = "...-"; a[23] = ".--"; a[24] = "-..-"; a[25] = "-.--"; a[26] = "--.."; string s1; while(cin >> s1) { int p = 0; int count = 0; for(int i = 0; i < s1.length(); i++) { if(s1[i] != '/') { count++; if(i == s1.length() - 1) { int sp = 0; for(int j = 1; j <= 26; j++) { if(a[j] == s1.substr(p,count)) { printf("%c",65 + j - 1); sp = 1; break; } } if(sp == 1) { cout << endl; break; } } } if(s1[i] == '/') { for(int j = 1; j <= 26; j++) { if(a[j] == s1.substr(p,count)) { printf("%c",65 + j - 1); p = i+1; count = 0; break; } } if(s1[i+1] == '/') { 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