08 2012 档案

摘要:这道题很有意思,需要巧妙地套用单调队列首先我们要明确几件事情1.假设我们现在知道序列(i,j)是符合标准的,那么如果第j+1个元素不比(i,j)最大值大也不比最小值小,那么(i,j+1)也是合法的2.如果(i,j)不合法的原因是差值比要求小,那在(i,j)范围内的改动是无效的,需要加入j+1元素充当最大值或者最小值才可能获得合法的序列3.假设序列(i,j)的差值比要求大,那么我们必须将其中的最大值... 阅读全文
posted @ 2012-08-30 08:45 编程菜菜 阅读(553) 评论(0) 推荐(0)
摘要:题意:很简单,不废话了- -在这道题中单调队列的作用:在线性时间内维护定长区间的最值。单调队列没学过的话去学一下这题吧转移的时候dp[i][k]->dp[i+1][j],k与j的差距不超过T,分两种情况转移,k在j的左边和右边,所以维护T长度的最值,双向扫一遍就OK了 (从右边扫过来) k j j k<--------T-------> <--------T-------> dp[i+j][... 阅读全文
posted @ 2012-08-29 21:50 编程菜菜 阅读(251) 评论(0) 推荐(0)
摘要:题意: 给定每天的股票买进上限,买进价格,卖出上限,卖出价格,每两次买卖操作中间必须间隔w天,每天最多持有maxp个股票,问n天后最大收益是多少题解: DP方程显然: dp[i][j]=max(不买不卖,买入操作,卖出操作)不买不卖 dp[i][j]=max(dp[i][j],dp[i-1][j])买 dp[i][j]=max(dp[pre][k]-(j-k)*AP[i]) dp[i][j]+j*... 阅读全文
posted @ 2012-08-29 17:12 编程菜菜 阅读(244) 评论(0) 推荐(0)
摘要:很裸的一道单调队列题(把数列扩大一倍即可),但是要注意题目的比较条件(定义比较函数),不然会WA代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N=100010;typedef pair<int,int> PII;int T,n,... 阅读全文
posted @ 2012-08-28 23:22 编程菜菜 阅读(162) 评论(0) 推荐(0)
摘要:斜率优化DP入门题O(n^2)方程: dp[i]=dp[j]+M+(sum[i]-sum[j])^2;用斜率优化掉枚举j的O(n)代码(含输入输出外挂):#include <iostream>#include <stdio.h>#include <string.h>using namespace std;const int N=500010;typedef long long LL;#define... 阅读全文
posted @ 2012-08-28 23:16 编程菜菜 阅读(146) 评论(0) 推荐(0)
摘要:斜率优化DP:未优化方程:dp[i]=dp[j]+C+(a[i]-a[j+1])^2;解法同HDU3507Trick: 检查斜率时不能用叉乘 直接检查即可(不然数字范围过大超long long会WA)代码:#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <math.h>usin... 阅读全文
posted @ 2012-08-28 23:16 编程菜菜 阅读(205) 评论(0) 推荐(0)
摘要:第一道斜率优化DP题方法:参考论文《浅谈数形结合思想在信息学竞赛中的应用》 的例2 构造凸包 求切点代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N=100010;int n,k;int a[N],sum[N];int que[... 阅读全文
posted @ 2012-08-27 11:15 编程菜菜 阅读(145) 评论(0) 推荐(0)
摘要:操作:1. 将 a b 区间染上颜色z2. 统计a b区间内颜色为z的点的个数此题若用普通线段树会退化成O(n)比赛时YY了一个map<int,int>的线段树 HLL的MLE了赛后才知道可以YY剪枝过 方法:记录区间被染的最小颜色和最大颜色 若查询颜色不在范围内则return (数据水了)更好的方法是标程上讲的分段Hash http://page.renren.com/601081183/not... 阅读全文
posted @ 2012-08-26 21:24 编程菜菜 阅读(452) 评论(0) 推荐(0)
摘要:第一个离散化线段树先把区间写成左开右闭的形式,然后sort() unique() lower_bound() 离散化最后按普通线段树更新即可代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define for if(0); else forcons... 阅读全文
posted @ 2012-08-15 11:56 编程菜菜 阅读(1015) 评论(0) 推荐(0)
摘要:刚开始做的时候还以为是暴搜,YY了各种剪枝,结果华丽丽的TLE了正解:状态压缩DP dp[当前走到的点][状态] 状态: 第i位表示第i个点有没有被消灭转移: 详见代码注意: 计算转移cost时要用O(1) 的算法 二分会TLE代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#includ... 阅读全文
posted @ 2012-08-13 22:40 编程菜菜 阅读(209) 评论(0) 推荐(0)
摘要:线段树扫描线经典题:求矩形面积并思想:对y轴坐标离散化 分别计算各个小矩形的面积#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N=513;struct Rect{double x1,y1,x2,y2;};struct Sline{do... 阅读全文
posted @ 2012-08-12 22:35 编程菜菜 阅读(225) 评论(0) 推荐(0)
摘要:给出一个长度为N(N<=100000)的数列,然后是五种操作:插入操作:0ab将所有[a,b]区间内的数改成01ab将所有[a,b]区间内的数改成12ab将所有[a,b]区间内的数异或一下(0边1,1变0)输出操作:3ab输出[a,b]区间内1的数量4ab输出[a,b]区间内最长的连续1串setbuf太坑了 一直TLE T_T去掉就过了#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define 阅读全文
posted @ 2012-08-09 11:38 编程菜菜 阅读(157) 评论(0) 推荐(0)
摘要:1Y爽歪歪线段树功能:1. 单点更新 2.查询区间递增子序列长度代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define for if(0); else forconst int N=100010;struct SegNode{int lval... 阅读全文
posted @ 2012-08-06 10:31 编程菜菜 阅读(150) 评论(0) 推荐(0)
摘要:线段树经典题线段树功能:1.区间覆盖2.查询区间最长连续1个数代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define for if(0); else forconst int N=65536+10;struct SegNode{int lsu... 阅读全文
posted @ 2012-08-06 09:34 编程菜菜 阅读(184) 评论(0) 推荐(0)
摘要:注:http://poj.org/problem?id=3278为此题的缩水版 BFS能过思路:Step1:将数转换为二进制Step2:因为有-1的操作 所以不能直接贪心 通过观察可得 b是a的二进制前缀与b是二进制的前缀+1同样重要 考虑 dp[位数][状态] (状态为前缀 和前缀+1)Step3:建立初值 dp[i][j]=abs(a-toBase10(b的前i+1位))Step4: if(b的二进制表示第i位==0) dp[i][0]=min(dp[i-1][0]+1,dp[i-1][1]+2)dp[i][1]=min(dp[i-1][0]+2,dp[i-1][1]+2)elsedp[i 阅读全文
posted @ 2012-08-05 21:20 编程菜菜 阅读(826) 评论(0) 推荐(0)
摘要:思路:先BFS出关键点(起点,电池,开关)之间的最短路然后状态压缩DP dp[当前位置][状态]=电池电量二分答案即可#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>using namespace std;const int N=16;#define for if(0); else forstruct Point{ int x,y; Point(){x=y=0;} Point(int xx,int y 阅读全文
posted @ 2012-08-05 17:15 编程菜菜 阅读(681) 评论(0) 推荐(0)