题面: Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The di…
有一个数列,对于每一个数,求比它小的在他右边距离他最远的那个数和他的距离 用单调队列做,维护单调队列时可采用如下方法,对于每一个数,如果队列中没有数,则加入队列,如果队列头的数比当前数大,则舍弃该数 对于此题,可用两个队列来维护,一个保存值,一个保持位置,每次查询对值进行二分,然后到对应保持位置的队列中求出结果 #include<map> #include<set> #include<cmath> #include<queue> #include<st…
题意: 给你n个数,让你从中选一个子集要求子集中的任何两个数相加都是质数. 思路: 一开始把自己坑了,各种想,后来发现一个简单的性质,那就是两个数相加的必要条件是这两个数之中必定一个奇数一个偶数,(除了含有1 集合以外,1+1等于2也是质数). 考虑两种情况,有1存在和1不存在这两种. 很显然1存在的情况下,所有的1都可以同时在集合中出现,要想集合最大不能加奇数,只能加偶数,那么我们看原始集合中是否有偶数加一是素数. 不考虑1的情况下,这样的子集最大是2,只有存在一个奇数一个偶数相加是质数的情况…
题目链接:http://poj.org/problem?id=2823 #include<iostream> #include<cstdio> #define M 1000001 using namespace std; int n,k; int a[M]; int q[M]; int p[M]; void get_min() { ; ; ;i<k-;i++) { while(head<=tail&&a[i]<=q[tail]) --tail; q…
F. Cutlet time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3706 Second My Problem First Time Limit: 12000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Give you three integers n, A and B. Then we define Si = Ai mod B and…
目录 #0.0 前置知识 #1.0 简单介绍 #1.1 本质 & 适用范围 #1.2 适用方程 & 条件 #2.0 例题讲解 #2.1 P3572 [POI2014]PTA-Little Bird #2.1.1 关于题面 #2.1.2 朴素算法 #2.1.3 单调性分析 #2.1.4 码代码 #2.2 P3089 [USACO13NOV]Pogo-Cow S #2.2.1 朴素算法 #2.2.2 单调性分析 #2.2.3 码代码 #3.0 单调队列优化多重背包 #3.1 分析 #3.2 码…
题意: 给你n个数,m次询问,每次询问给l和r代表l和r中间所有子区间中特征值的和. 特征值的定义是在这个区间中找i和j使得|tmp[i]-tmp[j]|/|j-i|最大. 思路: 首先是特征值的定义,这个东西其实是斜率~不知道从哪里看到的证明,这个只有相邻的点才可能最大.所以给定区间找到最大值其实是在相邻的中找.这是这题第一个关键点. 如果一个一个加寻找每一个区间那么复杂度应该是n^2,这里的n大小是1e5,还是不行.然后这个时候思路就是通过单调队列来解决啦~[个人认为更像是个DP]找到某个点…
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hierog…
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/319/B Description There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who h…