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,求要砍掉所有的头,需要的最少佣金是多少. ...
随机推荐
- [C++] wchar_t关键字使用方法
char 是单字符类型,长度为一个字节 wchar_t 是宽字符类型,长度为两个字节,主要用在国际 Unicode 编码中 举例: #include<iostream> using nam ...
- 三大框架 之 OGNL表达式
目录 OGNL 什么是OGNL OGNL与EL表达式对比 OGNL功能 OGNL使用要素 OGNL入门 java程序使用ognl struts2中使用ONGL OGNL 什么是OGNL OGNL是Ob ...
- java中nextLine()与next()的区别
java中的next()和nextLine()还是有很大区别的. next()一定要读取到有效字符后才可以结束输入,对输入有效字符之前遇到的空格键.Tab键或Enter键等结束符,next()方法会自 ...
- if ( ! defined('BASEPATH')) exit('No direct script access allowed')的作用
在看源代码时,发现codeigniter框架的控制器中,总是加上这样一段话: if(!defined('BASEPATH'))exit('No direct script access allowed ...
- Python3基础 运算 加减乘除、取余数
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- [译]如何在GitHub仓库创建一个标签tag, 并推送到远程分支?
问: 我在GitHub上有一个仓库,我需要给他打个tag.我在shell打了tag,但是在Github上没有显示出来.我还要做其他什么么? 我在shell中使用的命令是: git tag 2.0 当我 ...
- MySQL数据库查找多个字段值全部相同的记录
数据库中用户表,数据从第三方系统导入,由于一些垃圾数据,存在用户名和密码都相同的账户,造成接口上一些问题,SQL语句如下: and Account2>;
- Siamese Net
参考博客:https://blog.csdn.net/ybdesire/article/details/84072339
- Python - Django - session 的基本使用
urls.py: from django.conf.urls import url from app02 import views urlpatterns = [ # app02 url(r'^app ...
- 容器版jenkins安装并且实现使用宿主机docker命令,采用的是docker outside deocker,带jdk、添加maven、git
docker版jekins使用宿主机docker命令 docker版jekins安装,实现CI/CD,也就是实现在容器里面使用宿主机docker命令,这样方式为:docker outside deoc ...