上一页 1 ··· 3 4 5 6 7 8 下一页
摘要: /*若N个数 为递增序列则最多需要N个导弹系统贪心 + DP 见注释*/#include <stdio.h>#define MAX 100000int height[MAX]; //height[i]表示第i个防导弹系统所能防御的最大高度int t; //t个数int high; //height[i]中 最高高度 的 下标int a[MAX];int main(){ int i,j; //j 导弹系统个数 while(scanf("%d",&t)!= EOF){ scanf("%d",&a[0]); height[0] = 阅读全文
posted @ 2011-04-09 02:17 L.. 阅读(348) 评论(0) 推荐(0) 编辑
摘要: /*给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ...,Nj },其中 1 <= i <= j <= K。最大连续子序列是所有连续子序列中元素和最大的一个,例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{ 11, -4, 13 },最大和为20 状态转移方程 dp[i] = max(dp[i - 1] + a[i],a[i]) 最长公共子序列 求出最长的起点 和 终点*/#include <stdio.h>int main(){ int i,start,end,ma 阅读全文
posted @ 2011-04-09 02:09 L.. 阅读(337) 评论(0) 推荐(0) 编辑
摘要: 还得好好理解一下...为什么注释部分去掉 不能AC ? 知道的麻烦指导一下!#include <stdio.h>#define L(x) ((x) << 1)#define R(x) ((x) << 1 | 1)const int MAXN = 200000;struct SegTree{ int l,r; int metal; int value; bool lazy; int getMid(){ return ( l + r ) >> 1; } int getDis(){ return (r - l + 1); }}tree[MAXN < 阅读全文
posted @ 2011-04-09 01:12 L.. 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 给你一段数列 两个操作"Cabc" means addingcto each ofAa,Aa+1, ... ,Ab. -10000 ≤c≤ 10000. 一段区间同时增加一个值"Qab" means querying the sum ofAa,Aa+1, ... ,Ab.查询一段区间的值这题很好的体现了lazy_tag的思想,当要增加的区间覆盖当前区间,则直接打上标记返回,当下次查询这个区间儿子区间的时候,直接标记往下传。可以想象,这个标记表示的是这个区间表示的整个区间的标记,是整个子树的性质,当你不需要用到这个区间的儿子区间的时候,你可以不把操作都做到 阅读全文
posted @ 2011-04-08 16:48 L.. 阅读(318) 评论(0) 推荐(0) 编辑
摘要: /*p 横q 竖顺序...这题要按照字典序顺序搜索,深搜策略,判断成功的条件是走的步数等于格子的数目*/#include <stdio.h>#include <string.h>#define MAXN 27int map[MAXN][MAXN];int p, q, cas, ok, step;;int pathX[MAXN], pathY[MAXN];int dr[8][2] = {{-2, -1}, {-2, 1}, {-1, -2}, {-1, 2},{1, -2}, {1, 2}, {2, -1}, {2, 1}}; //字典序顺序int legal(int x 阅读全文
posted @ 2011-04-07 22:51 L.. 阅读(157) 评论(0) 推荐(0) 编辑
摘要: /*题目已按x,y轴排序 画个图就理解了*/#include <stdio.h>#include <stdlib.h>const int MAXN = 15001;int n;int a[32001]; //树状数组 int level[MAXN];int lowbit(int t){ return t & (-t); }void add(int t){ while(t <= 32001){ a[t]++; t += lowbit(t); }}int sum(int t){ int ans = 0; while(t > 0){ ans += a[t] 阅读全文
posted @ 2011-04-07 20:43 L.. 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 经典的染色问题,很明显的体现了lazy——tag思想.../*用cin超时...*/#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#define L(t) ((t) << 1)#define R(t) ((t) << 1 | 1)using namespace std;const int MAXN = 1000002;bool used[33];struct SegTree{ int l, r; int color; 阅读全文
posted @ 2011-04-07 20:41 L.. 阅读(206) 评论(0) 推荐(0) 编辑
摘要: /*第一类信息ll, rr, len递推求解第二类信息state.表示整个子树的性质*/#include <stdio.h>#include <algorithm>#define L(x) ((x) << 1)#define R(x) ((x) << 1 | 1)using namespace std;const int MAXN = 50002;int N, M;struct SegTree{ int l, r; int ll, rr; //最左边,右边可用连续区间长度 int len; //最长连续可用房间长度 int state; //0 阅读全文
posted @ 2011-04-07 20:33 L.. 阅读(355) 评论(0) 推荐(1) 编辑
摘要: //通过这题知道了可并堆这个东西.其实挺好理解的,体会到了//数据结构的强大啊!!!#include <stdio.h>#include <algorithm>using namespace std;const int MAXN = 100100;int father[MAXN];struct Monkey{ int l,r; int dis; int strong;}LTree[MAXN];int find(int x){ if(x != father[x]) father[x] = find(father[x]); return father[x];}int mer 阅读全文
posted @ 2011-04-07 17:45 L.. 阅读(641) 评论(0) 推荐(0) 编辑
摘要: 数状数组 模板题/*(1) Add i j,i和j为正整数,表示第i个营地增加j个人(j不超过30)(2)Sub i j ,i和j为正整数,表示第i个营地减少j个人(j不超过30);(3)Query i j ,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数;(4)End 表示结束,这条命令在每组数据最后出现;当然线段树也可以解决,不过没树状数组方便 哈哈*/#include <iostream>#include <stdlib.h>#include <string.h>using namespace std;const int MAXN = 阅读全文
posted @ 2011-04-07 17:23 L.. 阅读(178) 评论(0) 推荐(1) 编辑
上一页 1 ··· 3 4 5 6 7 8 下一页