摘要: 优先队列,据说标程是并查集,没思路。貌似优先队列都是直接用stl写的,又逼我用stl了。prioriry_queue不熟。ps: value值越小,优先级越高。所以重载 < 运算符时按优先级从大到小排序bool operator < (const node a, const node b) { if(a.day != b.day) return a.day > b.day; return a.type > b.type;}参考网上的代码View Code 1 #include <iostream> 2 #include <cstdio> 3 #i 阅读全文
posted @ 2012-04-01 21:11 AC_Von 阅读(402) 评论(0) 推荐(0) 编辑
摘要: 裸奔的矩阵乘法,当模板了。#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 2;const int MOD = 10000;struct Mat { long long mat[N][N]; void init() { for(int i = 0; i < N; ++i) { for(int j = 0; j < N; ++j) mat[i][j] = (i == j); }... 阅读全文
posted @ 2012-04-01 17:28 AC_Von 阅读(399) 评论(0) 推荐(0) 编辑
摘要: 据说,矩阵快速幂在递推式优化上相当神奇,而且效率很高。。。 两矩阵相乘,朴素算法的复杂度是O(N^3)。如果求一次矩阵的M次幂,按朴素的写法就是O(N^3*M)。既然是求幂,不免想到快速幂取模的算法,这里有快速幂取模的介绍,a^b %m 的复杂度可以降到O(logb)。如果矩阵相乘是不是也... 阅读全文
posted @ 2012-04-01 16:42 AC_Von 阅读(22980) 评论(9) 推荐(6) 编辑