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,求要砍掉所有的头,需要的最少佣金是多少. ...
随机推荐
- Communications link failure due to underlying exception: ** BEGIN NESTED EXC
一是将 wait_timeout=31536000 interactive_timeout=31536000 将过期时间修改为1年. 二是在连接URL上添加参数:&autoReconnect= ...
- Linux内存中的Cache真的能被回收吗? 【转】
在Linux系统中,我们经常用free命令来查看系统内存的使用状态.在一个RHEL6的系统上,free命令的显示内容大概是这样一个状态: [root@tencent64 ~]# free ...
- CMU Database Systems - Concurrency Control Theory
并发控制是数据库理论里面最难的课题之一 并发控制首先了解一下事务,transaction 定义如下, 其实transaction关键是,要满足ACID属性, 左边的正式的定义,由于的intuitive ...
- qemu通过控制台向虚拟机输入组合键
ctrl+alt+2 开启控制台 ctrl+alt+1 关闭控制台 在控制台中输入 sendkey ctrl-alt-delete 发送指令
- Visual Studio 2019更新到16.2.2
Visual Studio 2019更新到16.2.2 此次更新的变化有以下几点: (1)修复了Visual Studio在关闭时的停止响应问题.(2)修复CVE-2019-1211权限提升漏洞.(3 ...
- 卸载node和npm
sudo npm uninstall npm -g yum remove nodejs npm -y
- jenkins发布程序触发shell调用python脚本刷新akamai cdn api
刷新cdn的流程:jenkins获取git中的代码,触发脚本推送到生产环境中(即cdn的源站) --> 触发脚本获取git工作目录的更新列表,将更新列表拼凑成带域名信息的url,写入到目录中 - ...
- windows下新增项目本地通过git bash推送至远程github
本地E盘workspace目录下新增了spring-cloud-alibaba-demo项目,还没有编译过,没有target等不需要推送至git的文件,所以就直接用git bash丢到github了. ...
- Java Audio : Playing PCM amplitude Array
转载自:http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/java-audio-playing-pcm-amplitude-array.html ...
- div定位relative和absolute和float测试3
position等于absolute的时候,不一定是相对于浏览器定位,当div存在包含关系时,父div设置成relative,其中包含的div设置成absolute就是相对于该父div的了.该文测试了 ...