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,求要砍掉所有的头,需要的最少佣金是多少. ...
随机推荐
- Cesium原理篇:6 Renderer模块(1: Buffer)【转】
https://www.bbsmax.com/A/n2d9P1Q5Dv/ 刚刚结束完地球切片的渲染调度后,打算介绍一下目前大家都很关注的3D Tiles方面的内容,但发现要讲3D Tiles,或者充分 ...
- css 文本省略号显示
文本省略号是非常常见的需求,而省略号展示又通常分为俩种情况折行和不折行.不折行: div { white-space:nowrap;/* 规定文本是否折行 */ overflow: hidden;/* ...
- 微信小程序带cookie的request请求代码封装(小程序使用session)
微信小程序带cookie的request请求可,以使服务端知道是同一个客户端请求. session_id会不变,从而很好的使用服务端的session. 写一个工具函数,直接导入使用即可,接口同 wx. ...
- js怎么模拟点击网页元素
在测试页面中,引入jquery源文件,并添加一个div标签,一个a标签,为了演示效果a标签暂时不添加地址 通过jquery为div标签绑定一个点击事件,这个事件是被动执行的.意思是要点击才会触发的 在 ...
- 编程基础-c语言中指针、sizeof用法总结
1.指针 学习 C 语言的指针既简单又有趣.通过指针,可以简化一些 C 编程任务的执行,还有一些任务,如动态内存分配,没有指针是无法执行的.所以,想要成为一名优秀的 C 程序员,学习指针是很有必要的. ...
- linux内核挂载根文件系统时报错”VFS: Cannot open root device "ram0" or unknown-block(0,0): error -6“如何处理?
1. 通过error -6得到: #define ENXIO 6 /* No such device or address */ 2. 解决办法 使能CONFIG_BL ...
- Java基础 switch 表达式为字符串
JDK :OpenJDK-11 OS :CentOS 7.6.1810 IDE :Eclipse 2019‑03 typesetting :Markdown code ...
- 如何改为root用户 并挂载
改为root用户才能挂载,使用的命令是sudo su,换成自己就su + 名字就好了,比如bnrc. 进入root之后,执行命令mount /dev/sdb/ /diskb/,即mount + 使用的 ...
- 用filter求素数
计算素数的一个方法是埃氏筛法, 所有的奇数: def _odd_iter(): n = 1 while True: n = n + 2 yield n 定义一个筛选函数: def _not_divis ...
- C/C++ socket编程教程之九:TCP的粘包问题以及数据的无边界性
C/C++ socket编程教程之九:TCP的粘包问题以及数据的无边界性 上节我们讲到了socket缓冲区和数据的传递过程,可以看到数据的接收和发送是无关的,read()/recv() 函数不管数据发 ...