随笔分类 - POJ
摘要:http://poj.org/problem?id=1811View Code /*=====================================================*\| Miller Rabin 判断一个大数是不是素数 | Pollard 找出因子\*=====================================================*/#define inf 0x3f3f3f3f#define linf inf*inf#define SS 8//Miller测试次数#define C 240typedef long long ll;ll N,
阅读全文
摘要:http://poj.org/problem?id=3678典型的2-sat裸题View Code /*====================================================*\| 2-sat问题:判断某个数的0或1的取值是否存在满足条件的解\*====================================================*/const int MM = 222222;int N, M;bool inq[MM];int cur,cnt,belong[MM];int stack[MM], top,dfn[MM], low[MM];int
阅读全文
摘要:http://poj.org/problem?id=1330View Code const int MM = 22222;int N, in[MM], root;int head[MM],NE;struct Edge{ int u,v,next;}edge[MM];bool vis[MM];int ief,level;int dp[MM][17]; //节点数*2int E[MM], L[MM], H[MM]; //节点数*2int log_2(int x) { int res=-1; while(x) x>>=1,res++; return res;}void add...
阅读全文
摘要:http://poj.org/problem?id=3420View Code //矩阵乘法做递推Matrix mat(16,16);void get_init() { mat.reset(); mat(0,15)=mat(1,14)=mat(2,13)=1; mat(3,12)=mat(3,15)=mat(4,11)=1; mat(5,10)=mat(6,9)=mat(6,15)=1; mat(7,8)=mat(7,14)=mat(7,11)=1; mat(8,7)=mat(9,6)=mat(10,5)=1; mat(11,4)=mat(11,7)=...
阅读全文
摘要:http://poj.org/problem?id=2186View Code const int MM = 11111;#define debug puts("wrong")typedef __int64 int64;int N,M;vector<int>edge[MM];const int maxn = 11111; //节点数bool instack[maxn];int ief,top,bcnt,st[maxn];int low[maxn],dfn[maxn],belong[maxn];int out[MM];void get_data() { int i
阅读全文
摘要:http://poj.org/problem?id=2663View Code //放骨牌类问题,dfs枚举方法,递推。 const int MM = 1111;#define debug puts("wrong")typedef __int64 int64;int64 N,M,dp[111][11];void dfs(int64 row,int64 col,int64 pre,int64 now,int64 ss) { if(col>=3) { if(pre==7) dp[row][now]+=ss; return; } if((pre&(1<<
阅读全文
摘要:http://poj.org/problem?id=1095catalan数确定N个节点的二叉树的种数,左右分配节点确定id。View Code const int MM = 11111;const int maxn = 19;typedef __int64 int64;#define debug puts("wrong")int N;int cata[maxn];void get_cata() { int i,j,k; cata[0]=cata[1]=1; for(i=2;i<maxn;i++) { for(cata[i]=0,j=0;j<i;j++) cat
阅读全文
摘要:find a+b+c=d , 3sum problem 枚举dhttp://poj.org/problem?id=2549View Code const int MM = 111111;int N;int num[MM];void get_data() { int i,j,k; for(i=0;i<N;i++) scanf("%d",&num[i]);}//choose three number from a set,then a+b+c=0void threesum(int n,int*val) { int i,j,k,a,b,c,tmp,l; sort(v
阅读全文
摘要:http://poj.org/problem?id=1699状态压缩,预处理出任意两个串的最长前缀和后缀的公共部分,然后DP。View Code //POJ1699const int MM = 110;#define maxint 0x3f3f3f3fint N;int d[1<<11][11];char str[MM];int len[MM][MM];int fail[MM];char ch[21][MM];int cal(int s1,int s2) { int i,j,k,n,m,ans=0; n=strlen(ch[s1]+1); m=strlen(ch[s2]+1)...
阅读全文
摘要:http://poj.org/problem?id=3368一维RMQView Code //询问递增序列 [l,r] 间,出现次数最多的数的个数,分段后用RMQ询问最小值int id, d[MM][17], N, Q;int len[MM],pos[MM],b[MM];int log_2(int x) { int res=0; while(x>>=1) res++; return res;}void get_rmq() { int i,j,k,limit; for(i=1;i<=id;i++) d[i][0]=len[i]; k=log_2(id); ...
阅读全文
摘要://phi[i]记录的是 0~i 之间与i互质的数的个数http://poj.org/problem?id=2478View Code const int MM = 1000005;typedef __int64 int64;int64 N;int64 phi[MM];void get_phi() { int64 i,j,k; for(i=1;i<MM;i++) phi[i]=i; for(i=2;i<MM;i+=2) phi[i]>>=1; for(i=3;i<MM;i++) { if(phi[i]==i) { for(...
阅读全文
摘要:http://poj.org/problem?id=1753View Code struct GaussE { int a[MM][MM]; int x[MM]; // 解集 int equ, var; int free_x[MM]; // 记录不确定的变元. //初始化 GaussE(int e,int v):equ(e), var(v) {} void reset() { memset(a,0,sizeof(a)); memset(x,0,sizeof(x)); memset(free_x,0,sizeof...
阅读全文
摘要:View Code //POJ 1204#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define ROOT 0#define debug puts("wrong")const int MM=1010;const int MAX_NODE=100100;const int CHI=26;int L,C,W;int cnt;int len[MM];int ansx[MM], ansy[MM], ansk[MM];char text[MAX
阅读全文
摘要:资料:http://wenku.baidu.com/view/0a8cd3c5bb4cf7ec4afed0c4.html http://www.gamedev.net/page/resources/_/technical/artificial-intelligence/a-pathfinding-for-beginners-r2003学习A*所要做的题目:①第k短路②15数码③第k短简单路。
阅读全文
摘要:Quad Tiling矩阵乘法预处理出转移方程 code:这里
阅读全文
摘要:http://poj.org/problem?id=3974View Code //O(N)计算一个给定字符串的最长回文子串const int MM = 1111111; char str[MM],ch[MM<<2];int rad[MM<<2], N;void get_init() { int i,j,k;ch[0]='$', ch[1]='#'; for(i=0;str[i];i++) ch[(i<<1)+2]=str[i],ch[(i<<1)+3]='#'; N=(i<<1)+2,
阅读全文
摘要:From:http://hi.baidu.com/aekdycoin/item/90065df1b0f5b412ce9f32d6Wiki:http://en.wikipedia.org/wiki/Dancing_Links论文参考:http://gaoyunxiang.com/wp-content/uploads/2010/02/Dancing_Links.pdfDancing Linkshttp://acm.hust.edu.cn/problem.php?id=1017过程:http://en.wikipedia.org/wiki/Algorithm_X模板题,测试模板的正确性。http:/
阅读全文
摘要:参考资料:http://en.wikipedia.org/wiki/Gaussian_elimination习题集_From:这里http://poj.org/problem?id=3185http://poj.org/problem?id=2947http://poj.org/problem?id=1222
阅读全文
摘要:参考:http://www.matrix67.com/blog/archives/276DNA Sequence
阅读全文
摘要:资料:http://en.wikipedia.org/wiki/Delaunay_triangulation#Algorithmshttp://poj.org/problem?id=2820
阅读全文