IT民工
加油!
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 29 下一页
摘要: 线段树的成段更新,区间求和基础题。/*Accepted 4284K 1750MS C++ 1946B 2012-07-24 14:01:14*/#include<cstdio>#define lson l, m, rt << 1#define rson m + 1, r, rt << 1 | 1typedef long long LL;const int MAXN = 100005;LL add[MAXN << 2];LL sum[MAXN << 2];void PushUp( int rt ){ sum[rt] = sum[rt & 阅读全文
posted @ 2012-07-24 14:07 找回失去的 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 题意:有n个数,从1到n,打乱顺序,现输入n-1个数,第i个数表示序列中第1到i-1的数比第i个数小的个数.要求输出该序列。从后往前每次求“第k小”,如样例,第五个数前面有0个比它小的,它一定是1,将1在线段树中删除,再看第四个数,前面有1个比它小的,它就是2、3、4、5中第2小的,以此类推。线段树求第k小一般思路:数组中存放区间元素个数,自顶向下,左边个数小于k就走右边,并用k去掉左边个数,否则走向左边,直到叶子结点就是第k小。/*Accepted 264K 47MS C++ 1061B 2012-07-24 12:19:42*/#include<cstdio>... 阅读全文
posted @ 2012-07-24 12:27 找回失去的 阅读(318) 评论(0) 推荐(0) 编辑
摘要: 求区间最大值减去最小值的值,用线段树再好不过了,这里线段树的功能就是查询区间的最大值和最小值,没有单点更新。#include<cstdio>#include<algorithm>using namespace std;#define lson l, m, rt << 1#define rson m + 1, r, rt << 1 | 1const int MAXN = 500107;int Max[MAXN << 2], Min[MAXN << 2];int N, Q;void PushUp( int rt){ Max[r 阅读全文
posted @ 2012-07-24 11:05 找回失去的 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 将字符串0到n编号,然后建图。G[i][j]是边的权值等于两个字符串的差异。然后求出最小生成树的权值。第一次写堆优化的prim算法,堆优化的好处在于避免重复更新已经存在在生成树中的点的值,在n比较大的时候效果会很明显。/*Accepted 16128K 610MS C++ 1519B 2012-07-24 10:34:28*/#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<cstdlib>#include<iostream&g 阅读全文
posted @ 2012-07-24 10:41 找回失去的 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 这道题本来不难,但是写的纠结。三维广搜,只有六个方向,有一段时间没写结构体,发现很不熟练。/*Accepted 612K 16MS C++ 2362B 2012-07-23 17:48:55*/#include<cstdio>#include<cstring>#include<cstdlib>#include<queue>using namespace std;const int MAXN = 50;const int dx[] = { 1, -1, 0, 0, 0, 0};const int dy[] = { 0, 0, 1, -1, 0, 0 阅读全文
posted @ 2012-07-23 17:52 找回失去的 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 括号序列,刘汝佳黑书上的经典例题。但是这道题要输出我们最后得到的添加括号最少的序列,输出序列确实很麻烦,参考了题解,才勉勉强强写出来,以后还得把这道题敲一遍。/*Accepted 288K 32MS C++ 1862B 2012-07-23 11:46:07*/#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;#define o -2#define lr -3const int MAXN = 105;int f[MAXN 阅读全文
posted @ 2012-07-23 11:53 找回失去的 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 现在给出两个碱基序列,可以在两个串间插入‘-’即空白,求两串的最大相似度。最长公共子序列的变形状态转移方程:f[i][j] = Max( f[i - 1][j] + score[dna(a[i])][4], f[i][j - 1] + score[4][dna(b[j])], f[i - 1][j - 1] + score[dna(a[i])][dna(b[j])])/*Accepted 216K 0MS C++ 1329B 2012-07-23 09:19:46*/#include<cstdio>#include<cstring>#include<algorit 阅读全文
posted @ 2012-07-23 09:37 找回失去的 阅读(149) 评论(0) 推荐(0) 编辑
摘要: http://www.rqnoj.cn/Problem_98.html裸的多重背包#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int N, V;const int MAXV = 1 << 9;int f[MAXV];void ZeroOnePack( int f[], int C, int W){ int v; for( v = V; v >= C; v --) f[v] = max( f[v], f[v - C] + W);}void Co 阅读全文
posted @ 2012-07-20 18:02 找回失去的 阅读(178) 评论(0) 推荐(0) 编辑
摘要: http://www.rqnoj.cn/Problem_217.html#include<cstring>#include<cstdlib>#include<cstdio>const int MAXN = 1005;int s[MAXN], top, t[MAXN];int cnt, hight[MAXN], cur;int N;int main(){ while( scanf( "%d", &N) == 1) { cnt = 1, top = 1; for( int i = 1; i <= N; i ++) { sc... 阅读全文
posted @ 2012-07-20 17:59 找回失去的 阅读(241) 评论(0) 推荐(0) 编辑
摘要: http://www.rqnoj.cn/Problem_6.html#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int MAXN = 32100;const int MAXM = 65;int f[MAXM][MAXN];int c[MAXM][3], w[MAXM][3];int n, m;void Pack(){ int i, j; for( i = 1; i <= m; i ++) for( int j = 0; j <= n; 阅读全文
posted @ 2012-07-19 18:29 找回失去的 阅读(143) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 29 下一页