【洛谷P4393】Sequence】的更多相关文章

题目大意:有$T(T\leqslant10^5)$组询问,每次求$A_n(n\leqslant10^{18})$:$$A_n=\left\lceil\left(\dfrac{\sqrt5+1}2\right)^n\right\rceil$$题解:通过打表看题解发现,这个序列是$2,3,5,7,\dots$,即$A_n=A_{n-1}+A_{n-2}-[n\equiv0\pmod2]$,题解中说可以记录三个信息矩阵快速幂一下,然后我并不会处理$[n\equiv0\pmod2]$(果然我最菜) 继续…
题目大意:给定一个长度为 N 的序列,每次可以合并相邻的两个元素,代价是两者中较大的值,合并之后的值也为两者较大的值,求合并 N-1 次后的最小代价是多少. 题解: 除了最大值以外,每个值均只会被合并一次,合并的代价一定是这个值左边最大值和右边最大值中较小的那一个.问题转化成了如何求解每个元素左边和右边第一个大于该元素的值,单调栈扫一遍即可. 注意:如果有相同的元素,如4 2 2 3,中间两个 2 在最后计算答案时会产生错误,避免的方式是计算每个元素右边的值取大于等于,左边取大于即可. 代码如下…
题目描述 小强喜欢数列.有一天,他心血来潮,写下了三个长度均为n的数列. 阿米巴也很喜欢数列.但是他只喜欢其中一种,波动数列. 阿米巴把他的喜好告诉了小强.小强便打算找出这三个数列内的最长波动数列. 也就是说,如果我们将三个数列记做a[n][3],他必须要构造一个二元组序列:<p[i], q[i]>,使得对于任何 i>1 有: p[i] > p[i-1] 若q[i] = 0,a[p[i]][q[i]] >= a[p[i-1]][q[i-1]] 若q[i] = 1,a[p[i]…
P4597 序列sequence 题目背景 原题\(\tt{cf13c}\)数据加强版 题目描述 给定一个序列,每次操作可以把某个数\(+1\)或\(-1\).要求把序列变成非降数列.而且要求修改后的数列只能出现修改前的数. 输入输出格式 输入格式: 第一行输入一个\(n\),表示有\(n(n \leq 5\times10^5)\)个数字. 第二行输入\(n\)个整数,整数的绝对值不超过\(10^9\) 输出格式: 输出一个数,表示最少的操作次数 发现之前洛谷做过一个类似的..P2893 che…
洛谷题目传送门 分数其实就是一个幌子,实际上就是求互质数对的个数(除开一个特例\((1,1)\)).因为保证了\(a<b\),所以我们把要求的东西拆开看,不就是\(\sum_{i=2}^n\phi(i)\)吗? 关于通过筛素数线性求欧拉函数的一点思路总结在蒟蒻的blog里 剩下的就是记一个前缀和了. #include<cstdio> #define R register const int N=1000001; int pr[N],phi[N]; long long ans[N]; bo…
题目 :Bovine Genomics G奶牛基因组 传送门: 洛谷P3667 题目描述 Farmer John owns NN cows with spots and NN cows without spots. Having just completed a course in bovine genetics, he is convinced that the spots on his cows are caused by mutations in the bovine genome. At…
To 洛谷.1432 倒水问题 题目背景 In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This…
题目传送门 MEG 题目描述 Byteotia has been eventually touched by globalisation, and so has Byteasar the Postman, who once roamedthe country lanes amidst sleepy hamlets and who now dashes down the motorways. But it is those strolls inthe days of yore that he re…
洛谷题目链接:[USACO06DEC]牛奶模式Milk Patterns 题目描述 Farmer John has noticed that the quality of milk given by his cows varies from day to day. On further investigation, he discovered that although he can't predict the quality of milk from one day to the next,…
洛谷题目链接:[POI2007]TET-Tetris Attack 题目描述 A puzzle called "Tetris Attack" has lately become a very popular game in Byteotia. The game itself is highlysophisticated, so we shall only introduce its simplified rules: the player is given a stack of \(2…