07 2019 档案
摘要:输入输出优化: 最近遇到一个题,照我的思路差100ms才能过,于是想尽一切办法做微小优化试图卡过去,最后虽然过去了,但要是会优化输入就更好了,于是学习一下这个模板备用 以下模板,具体讲解参考参考文章 代码: 参考文章: Felix Lee,C++ 读入优化与输出优化 模板,https://blog.
阅读全文
摘要:原理: 有好的博客做讲解了(见参考文章),这里暂时略过,如果以后有新的理解和体会会再来写的。~~(应该不会)~~ 思想: 这里可以把树状数组的精妙之处提一下(我理解的) 首先,树状数组之所以叫树状数组,因为它像树一样,有类似树的父子节点关系,这点在更新和求和操作上体现的最为明显。而最终也只是数组,因
阅读全文
摘要:题目描述: 给一个椭圆,上面有n个点,两两连接这n个点,得到的线段能把椭圆分为几个区域? 思路: 首先想想,n个点在椭圆边缘,每两个点两两连接有$C^2_n$条线段,这些线段交于很多点,求这些线段最多把椭圆分成几个部分。 考虑到欧拉公式:在平面图中$V E+F=2$,$V$为顶点数,$E$是边数,$
阅读全文
摘要:题目描述: E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are g
阅读全文
摘要:方法概述: 算法1:暴力枚举所有连续子列和,算其中最大的。复杂度$O(n^3)$。 算法2:为算法1的优化,去掉内层求连续和的循环,在之前遍历数组,预处理出前缀和,方便在$O(1)$内算出连续子列和。复杂度$O(n^2)$。 算法3:分治法,当前处理区间的连续和等于左边最大连续和与右边连续和与跨区间
阅读全文
摘要:题目描述: C. Elections time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As you know, majority
阅读全文
摘要:题目描述: B. Minimum Possible LCM time limit per test 4 seconds memory limit per test 1024 megabytes input standard input output standard output You are g
阅读全文
摘要:正常文本开头 include using namespace std; int main() { cout
阅读全文
摘要:思路:见参考文章(原理我是写不粗来了) 代码: 用到了快速幂,米勒罗宾素性检验。 其他分解质因数的方法: 朴素算法:枚举从2到n找n的因子,找到了就不断除,除到不能除为止,再找下一个因子。 为什么保证是素因子,从二开始,假设有二的因子,不断地除直到没有二就能保证二的倍数也没有了。类似于素数筛的思想。
阅读全文
摘要:适用范围:较大数的较快素性判断 思路: 因为有好的文章讲解具体原理(见参考文章),这里只是把代码的大致思路点一下,读完了文章如果还有些迷糊,可以参考以下解释 原理是费马小定理:如果p是素数,则a^(p-1)%p==1,加上二次探测定理:如果p是一个素数,则x^2%p==1的解为,则x=1或者x=n-
阅读全文
摘要:快速幂: 计算a^n%p的值,怎么算呢?直接算当然可能溢出。我们有一条引理:(a*b)%p=((a%p)*(b%p))%p.在这个引理上进行指数上的合并从而得到快速幂算法。 具体地,有两种思路,一种是减小a值,以防溢出,一种是减小b值,加快计算。 怎么减小a值?a=a%p,就把a的值降到了p以下。对
阅读全文
摘要:题目描述: F. Ant colonytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMole is hungry again. He found
阅读全文
摘要:思想: 先用字符串来读入大整数,然后用数组来存储大整数。与上一篇的所讲思路不同的是,这次是数组的每一个元素对应大整数的一个数,从而模拟手算过程。 主要实现思路与手算无太大差别。主要是一些细节上。 统一做个说明:模拟大数的数组的第零个元素保存的是数字个数(不包括第零个元素),而且数组从1到尾分别存大数
阅读全文
摘要:思想: 由于编程语言提供的基本数值数据类型表示的数值范围有限,不能满足较大规模的高精度数值计算,因此需要利用其他方法实现高精度数值的计算,于是产生了大数运算。大数运算主要有加、减、乘三种方法。 考虑用数组存储整数,并模拟手算的方法进行加减乘除四则运算。为了能像int一样方便的使用大整数,可以定义结构
阅读全文
摘要:题目描述: time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDima worked all day and wrote down on a lo
阅读全文
摘要:题目描述: D. Vus the Cossack and Numbers Vus the Cossack has nn real numbers aiai. It is known that the sum of all numbers is equal to 00. He wants to cho
阅读全文
摘要:题目描述: Nick had received an awesome array of integers a=[a1,a2,…,an] as a gift for his 5 birthday from his mother. He was already going to explore its
阅读全文
摘要:题目描述: D. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output D. Color the Fe
阅读全文
摘要:题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output 题目描述: H. Maximal GCD
阅读全文
摘要:题目描述: Description This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substrin
阅读全文
摘要:题目描述: A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Given a simple graph
阅读全文
摘要:子集生成算法: 给定一个集合,枚举所有可能的子集。暂时讨论没有重复元素的情况。 1 增量构造法 一次选出一个元素放到集合中,和前面不同,由于A中的元素个数不确定,每次递归都要输出当前集合。另外递归边界也不需要显式确定-如无法添加元素,就不会递归了。 注意:定序,规定集合A的所有元素的编号从小到大排列
阅读全文
摘要:想不想打印所有排列? 输入整数n,按字典序从小到大输出前n个数的所有排列。 1 生成1~n的排列 伪代码: 下面考虑程序实现。用数组A表示序列A,集合S 不用保存,因为它可以有序列A 完全确定-A中没有出现的元素都可以选。 代码: 循环变量i是当前考察的A[cur],上面的程序用到了一个标志变量ok
阅读全文
摘要:题目描述: B. Shaass and Bookshetime limit per test 2 secondsmemory limit per test 256 megabytesinput standard inputoutput standard outputShaass has n book
阅读全文
摘要:题目描述: 输入输出: 输入样例:
阅读全文
摘要:题目描述: 墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问。墨墨会向你发布如下指令: 1、 Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同颜色的画笔。 2、 R P Col 把第P支画笔替换为颜色Col。 为了满足墨墨的要求,你知道你需要干什么了吗?
阅读全文
摘要:题目描述: Problem DescriptionAn array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 ≤ l
阅读全文
摘要:说明: GCC provides a large number of built-in functions other than the ones mentioned above. Some of these are for internal use in the processing of exc
阅读全文
摘要:题目描述: D. Interesting Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe'll call an array of
阅读全文
摘要:题目描述: In this problem we consider a very simplified model of Barcelona city.Barcelona can be represented as a plane with streets of kind x=cx=c and y=
阅读全文
摘要:题目描述: C. Neko does Maths time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output C. Neko does Mat
阅读全文
摘要:题目描述: time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are preparing for an exam on schedulin
阅读全文
摘要:思路: 刚开始: 利用map来统计长度为k的一段上的数字及其出现次数,不断更新区段位置,减去退出区段的数字的出现次数,加上新出现的数字及其出现次数,每次都从后向前遍历一遍map,如果遇到一个数且出现次数为1,那么他就是当前区段上的最大数(因为map中已排好序),break,当前循环结束。这种方法果然
阅读全文
摘要:题目描述: 知识点: lower_bound和uper_bound lower_bound(起始地址,结束地址,要查找的数值) 返回的是数值 第一个 出现的位置。 upper_bound(起始地址,结束地址,要查找的数值) 返回的是数值 最后一个 出现的位置。 binary_search(起始地址,
阅读全文
摘要:这是我初学线段树时的一些学习记录,主要参考了其他一些博客(见参考文章),再加上基本的代码实现 一、线段树的概念 线段树擅长处理区间,树上的每个节点都维护一个区间,根维护的是整个区间,每个节点维护的是父亲节点区间二等分后的其一子区间。当有n个元素时,对区间的操作可以在O(log n)时间内完成。 二、
阅读全文
摘要:以下为初次阅读忒休斯之船过程中整理记下的记录,方便继续阅读时取阅: 忒修斯之船(一) 在忽略一切笔记的情况下只读忒修斯之船这部虚构的小说感受最深的便是其中细腻的景物,心理描写,感觉像极了《1984》。 疑问: 穿大衣的男人身份之谜? 本书是否由石察卡所写? K族是一个什么样的存在? 小说的背景是第二
阅读全文