摘要: 给出一个长度为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 编程菜菜 阅读(142) 评论(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 编程菜菜 阅读(140) 评论(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 编程菜菜 阅读(168) 评论(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 编程菜菜 阅读(795) 评论(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 编程菜菜 阅读(667) 评论(0) 推荐(0) 编辑