摘要: 二维树状数组用于求子矩阵的和。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <iostream> 8 #include <cmath> 9 #include <cstring>10 #include <algorithm>11 #include <string>12 #include <utility>13 #include <vec 阅读全文
posted @ 2012-10-13 22:48 發_ 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 枚举所有情况,每个位置可能变也可能不变,复杂度O(2^16)。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <iostream> 8 #include <cmath> 9 #include <cstring>10 #include <algorithm>11 #include <string>12 #include <utility>13 阅读全文
posted @ 2012-10-10 22:50 發_ 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 题意:给定原图顶点间的最短路,问原图最少有几条边。分析:若两点的距离可由另外两条边来代替,则可删去该边;若存在比这两点的距离更短的路径,则“impossible”.View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <iostream> 8 #include <cmath> 9 #include <cstring>10 #include <algorithm>11 #i 阅读全文
posted @ 2012-09-24 10:55 發_ 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 按H排序,每次查询把不大于H的值插入到树状数组中的相应位置并完成查询。171MSView Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <iostream> 8 #include <cmath> 9 #include <cstring> 10 #include <algorithm> 11 #include <string> 12 #include <ut 阅读全文
posted @ 2012-09-23 23:18 發_ 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 题解:对于期望值,一般定义的Ex都是表示离目标状态还需要的代价所以这里定义E[i]表示当前状态为i离结束还需要代价的期望值,那答案就是E[0]。对于期望类问题,一般解法是列出方程式,若状态之间存在环,则可采用高斯消元解方程组,也可想办法消环;反之,则可直接递推来求出目标状态。对于该题:E[x]=0 (x>n);E[i]=∑Pk*E[i+k]+P0*E[0] + 1;设 E[i] = a[i]*E[0] + b[i];联合上面的式子可消去E[i+k],可得E[i] = ( ∑Pk*a[i+k] + P0 )*E[0] + ∑Pk*b[i+k] + 1;可得出:a[i] = ∑Pk*a[i+ 阅读全文
posted @ 2012-09-23 01:05 發_ 阅读(260) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1273增广路算法。Ford_Fullkerson 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 #include 17 #include 18 using namespace std; 19 20 ty... 阅读全文
posted @ 2012-09-22 09:40 發_ 阅读(169) 评论(0) 推荐(0) 编辑
摘要: http://codeforces.com/problemset/problem/225/B思路:维护一个长度为k的队列,利用第k个k-bonacci数等于前面k个k-bonacci数的和,求出所有不大于s的k-bonacci数,可以用一个set来记录,然后每次贪最接近s的数。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <iostream> 8 #include <cmath> 9 # 阅读全文
posted @ 2012-09-20 17:23 發_ 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 250.找最长无重复子串。500.从val的范围入手(0~1023),bfs。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <iostream> 8 #include <cmath> 9 #include <cstring>10 #include <algorithm>11 #include <string>12 #include <vector 阅读全文
posted @ 2012-09-14 12:18 發_ 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 题意:给出n个2*2的矩阵,有m个查询,问某段区间的矩阵乘积。由于矩阵乘积符合结合律,故可用线段树来完成。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <iostream> 8 #include <cmath> 9 #include <cstring>10 #include <algorithm>11 #include <string>12 #incl 阅读全文
posted @ 2012-09-11 21:48 發_ 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 250.解三元一次方程组。View Code 1 class PlatypusDuckAndBeaver 2 { 3 public: 4 int minimumAnimals(int a, int b, int c) 5 { 6 int k = (2*b+4*c-a)/2; 7 int x = b - k; 8 int y = c - k; 9 return x + y + k;10 }11 };500.二分答案。View Code 1 typedef long long LL; 2 class... 阅读全文
posted @ 2012-08-23 20:47 發_ 阅读(127) 评论(0) 推荐(0) 编辑