Loading

随笔分类 -  算法之旅

摘要:题目链接: https://www.acwing.com/problem/content/1272/ 题解: 线段树模板题,单点求和、区间查询都可 AC代码: #include <cstdio> #include <iostream> #include <algorithm> #include <c 阅读全文
posted @ 2020-02-16 22:03 Doubest 阅读(143) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/description/1266/ 题解: 模板题,记query()、add()、lowbit()函数即可 AC代码: #include <iostream> #include <cstdio> #includ 阅读全文
posted @ 2020-02-16 09:26 Doubest 阅读(184) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/790/ 题解: 左边部分的下标必定小于右边部分的下标,且左右两边都排好序了,计算即可。 AC代码: #include <iostream> #include <cstring> #include <cstdi 阅读全文
posted @ 2020-02-14 14:27 Doubest 阅读(150) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/description/789/ 题解: 1、找分界点。 2、分别排序 3、归并 递归实现 AC代码: #include <cstdio> #include <cstring> #include <iostre 阅读全文
posted @ 2020-02-14 13:34 Doubest 阅读(254) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/1233/ 题解: (飞行时间+时差 + 飞行时间 - 时差) / 2 = 飞行时间 AC代码: #include <cstdio> #include <cstring> #include <iostream> 阅读全文
posted @ 2020-02-13 22:43 Doubest 阅读(259) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/1231/ 题解: 估计自己太弱了,处理字符串比较痛苦,最后记得用unique去重。 代码: #include <cstring> #include <cstdio> #include <string> #in 阅读全文
posted @ 2020-02-12 15:54 Doubest 阅读(242) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/1221/ 题解: 对于分子分母都是整数的除法,例如a/b,除了可以用ceil()函数向上取整外,还可以直接用公式(a+b-1)/b; 代码: #include <algorithm> #include <io 阅读全文
posted @ 2020-02-12 14:37 Doubest 阅读(196) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/1206/ 题解: (1)getline()不会读\n,并且会抛弃读到的\n,而且不会留在缓冲区中。 (2)cin不会读\n,但是会把它留在缓冲区中等其他人读入 (3)stringstream在字符串、数字互转 阅读全文
posted @ 2020-02-11 22:16 Doubest 阅读(242) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/1216/ 题解: 一定要注意对于负数取余,要用数学上的定义,必须>=0 最后那个s也要记得用函数取余 AC代码: #include <iostream> #include <algorithm> #inclu 阅读全文
posted @ 2020-02-10 16:26 Doubest 阅读(296) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/description/1214/ 题解: DP问题混合怪兽 AC代码: #include <cstring> #include <iostream> #include <algorithm> #include 阅读全文
posted @ 2020-02-10 14:53 Doubest 阅读(168) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/897/ 题解: 一维DP问题,非常经典 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> 阅读全文
posted @ 2020-02-09 16:50 Doubest 阅读(104) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/2/ 题解: 关于DP问题,我们一般可以用一套模式去分析 1、分析状态表示f(i,j): 1)f(i,j)表示哪个集合?在01背包问题中,它表示选法的一个集合 2)i,j表示什么条件?在01背包问题中,它表示前 阅读全文
posted @ 2020-02-09 11:08 Doubest 阅读(118) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/101/ 题解: 边界问题最复杂,画图好好模拟一下,二维前缀和还是比较容易的 枚举的所有的边长为R的正方形,AC代码是枚举的正方形的左上端点。 AC代码: #include <cstdio> #include 阅读全文
posted @ 2020-02-08 13:07 Doubest
摘要:题目链接: https://www.acwing.com/problem/content/1232/ 题解: 这个公式最重要s[r] - s[l-1] % k == 0 等价于 s[r]%k == s[l-1] % k 意思就是说,只要s[n]和s[m]模k的值一样,他们必然可以组成一个k倍区间 边 阅读全文
posted @ 2020-02-07 19:06 Doubest 阅读(107) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/798/ 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 100 阅读全文
posted @ 2020-02-07 14:24 Doubest 阅读(145) 评论(0) 推荐(0)
摘要:题目链接: https://www.acwing.com/problem/content/732/ 题解: 这个题最重要的一点就是:用初始值丈量能不能行时,一定要及时停止,不然连long long都给你爆了。 二分的两个边界: l = (min + 1) / 2 r = max 原因是: x + x 阅读全文
posted @ 2020-02-06 13:55 Doubest 阅读(259) 评论(0) 推荐(0)
摘要:给定一个按照升序排列的长度为n的整数数组,以及 q 个查询。 对于每个查询,返回一个元素k的起始位置和终止位置(位置从0开始计数)。 如果数组中不存在该元素,则返回“-1 -1”。 输入格式 第一行包含整数n和q,表示数组长度和询问个数。 第二行包含n个整数(均在1~10000范围内),表示完整数组 阅读全文
posted @ 2020-02-06 11:35 Doubest 阅读(112) 评论(0) 推荐(0)
摘要:Description Input Output 当时做题时,思路没问题,但是有一个很大的问题就是自己在编程时没化简表达式,n*m 爆了 int,还有一个点就是,向上去整没用好! #include <bits/stdc++.h> using namespace std; int main() { d 阅读全文
posted @ 2019-12-15 20:55 Doubest 阅读(108) 评论(0) 推荐(0)
摘要:这个题最烦的地方就是题意有点点含糊 首先是“另外相邻的两部分不能存在包含关系”这句话的理解,这句话的最准确翻译就是 两个字符串接龙之后 不能等于其中任何一个字符串 其次就是两个字符串接龙时,如果有多种接法,使用最长那一种 AC代码如下: #include <bits/stdc++.h> using 阅读全文
posted @ 2019-12-07 17:41 Doubest 阅读(245) 评论(0) 推荐(0)
摘要:埃拉托斯特尼筛法,简称埃氏筛或爱氏筛,是一种由希腊数学家埃拉托斯特尼所提出的一种简单检定素数的算法。要得到自然数n以内的全部素数,必须把小于等于根号n的所有素数的倍数剔除,剩下的就是素数。 这是什么意思呢? 以100为例,我们先创建一个拥有101(0-100)个数字的数组。 先使用最小的素数2,将所 阅读全文
posted @ 2019-12-01 13:21 Doubest 阅读(995) 评论(0) 推荐(0)