RMQ(鸽巢原理或字符串操作)】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8310    Accepted Submission(s): 3296 Problem Description Kiki likes traveling. One day…
题目大意: 给你一个数字字符串序列,给你要求删掉的数字个数m,删掉m个数使的剩下的数字字符串的之最小.并输出这个数字: 基本思路; 这题解法有很多,贪心,rmq都可以,这里选择rmq,因为很久没有写rmq的题目了,所以这里先来一发. 至于鸽巢原理,这应该是一个很显而易见的道理,自己去脑补吧. 代码如下: #include<iostream> #include<cstdio> #include<string> #include<cstring> #includ…
题意 给定长为 \(n\) 序列 \(a\) ,要求支持两种操作: \(1.\) 询问在一个区间 \([l,r]\) 中,是否能够选出两个交集为空的集合 $ \rm X ,Y$, 使得 \(\sum_{i\in \rm X}{a_i}=\sum_{j\in \rm Y}{a_j}\). \(2.\) 将区间 \([l,r]\) 中的每个数字取立方并对 \(v\) 取模. \(n\leq 10^5,v\leq 10^3\) . 分析 对于 \(1\) 操作 ,如果区间长度 \(len>13\) 一…
题意:给你N个数,从中取出任意个数的数 使得他们的和 是 N的倍数: 在鸽巢原理的介绍里面,有例题介绍:设a1,a2,a3,……am是正整数的序列,试证明至少存在正数k和l,1<=k<=l<=m,是的和ak+ak+1+……+al是m的倍数,接下来开始证明: 构造一个序列s1=a1,s2=a1+a2,……,sm=a1+a2+……+am,那么会产生两种可能: 1:若有一个sn是m的倍数,那么定理成立: 2:假设上述的序列中没有任何一个元素是m的倍数,令rh ≡ sh mod m;其中h=1,…
题意:有两个长度为n的排列p和s.要求通过交换使得p变成s.交换 pi 和 pj 的代价是|i-j|.要求使用最少的代价让p变成s. 考虑两个数字pi和pj,假如交换他们能使得pi到目标的距离减少,pj到目标的距离减少.那么应该交换他们,这是一个必要的操作,也是答案的下界. 如果每一次都能找到这样的两个数字,那么答案就是排列p中的每个数字在排列s的位置的距离差之和/2.这显然是答案的下界. 现在考虑证明这个下界是可以构造出来的. 考虑排列p中最后一个位置不对的数字,不妨设为pj,他的目标位置是p…
题意:将一列数划分为两个等差数列. 思路:首先,我要吹爆鸽巢原理!!!真的很强大的东西!!! 加入能完成题设操作,则前三个数中,必有至少两个数在同一序列,枚举三种情况(a1 a2,a2 a3,a1 a3分别为等差数列的前两项). 注:枚举情况时,如果操作失败,则将已成功生成的等差数列末项划分到另一个数列试试.(稍作思考即可) 代码如下: #include<cstdio> #include<iostream> #include<cstring> using namespa…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798   Special Judge Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a sequence of numbers a1, a2, ..., an, and a number m. Check if it is possible to choose a non-empty subsequence…
Description The input contains N natural (i.e. positive integer) numbers ( N <= ). Each of that numbers . This numbers are not necessarily different (so it may happen that two or more of them will be equal). Your task <= few <= N ) so that the su…