上一页 1 ··· 26 27 28 29 30 31 32 33 34 ··· 36 下一页

2011年3月23日

poj 3422

摘要: 费用流,数据很水。代码:#include<iostream>#include<fstream>using namespace std;#define oo 10000000typedef struct e{ int data; e *next,*opt; int c,cost; }e;e edge[5003];int n,m;int v[5003],d[5003];int path[5003];e *path1[5003];int spfa(){ int queue[5005],i,j,k; memset(v,0,sizeof(v)); for(i=0;i<=n* 阅读全文

posted @ 2011-03-23 18:52 宇宙吾心 阅读(457) 评论(0) 推荐(0)

poj 2409

摘要: 分两种情况讨论:旋转:n种旋转方法每种旋转i个格(1<=i<=n)循环结有gcd(i,n)个翻转:(1)这种是经过某个顶点i与中心的连线为轴的翻转,由于n为偶数,有对称性,所以此种共n/2种翻转:(2)这种是以顶点i和i+1的连线的中点与中心的连线为轴的翻转,同样,根据对称性,也有n/2种翻转:所以给定长度n,共有2n种置换。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;int gcd(int s,int t){ if(t==0) return s 阅读全文

posted @ 2011-03-23 16:57 宇宙吾心 阅读(582) 评论(0) 推荐(0)

2011年3月19日

poj 3683

摘要: 艰难的ac。代码:#include<iostream>#include<fstream>#include<vector>using namespace std;vector<int> edge[2001],edge2[2001];int n,m;int v[2001],low[2001],dfn[2001],stack[2001],scc[2001],tot,index,top;void tarjan(int s){ int i,j,k; dfn[s]=low[s]=++index; stack[++top]=s; v[s]=1; for(i=0 阅读全文

posted @ 2011-03-19 20:48 宇宙吾心 阅读(594) 评论(0) 推荐(0)

poj 3648

摘要: 2sat,注意题意。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int data; e *next;}edge[121],edge2[122];int n,m;int v[121],low[121],dfn[121],stack[121],scc[121],tot,index,top;void tarjan(int s){ int i,j,k; dfn[s]=low[s]=++index; stack[++top]=s; v[s]=1; e *p=edge[s].next; wh 阅读全文

posted @ 2011-03-19 18:03 宇宙吾心 阅读(509) 评论(0) 推荐(0)

poj 2749

摘要: 2sat。邻接表会超时。代码:#include<iostream>#include<fstream>#include<cmath>#include<vector>using namespace std;vector<int> edge[1001],edge2[1001];int n;int v[1001],low[1001],dfn[1001],stack[1001],scc[1001],tot,index,top;void tarjan(int s){ int i,j,k; dfn[s]=low[s]=++index; stack[ 阅读全文

posted @ 2011-03-19 16:23 宇宙吾心 阅读(395) 评论(0) 推荐(0)

poj 2723

摘要: 2sat直接过。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int data; e *next;}edge[2300];int n,m;int v[2300],low[2300],dfn[2300],stack[2300],scc[2300],tot,index,top;void tarjan(int s){ int i,j,k; dfn[s]=low[s]=++index; stack[++top]=s; v[s]=1; e *p=edge[s].next; while(p){ 阅读全文

posted @ 2011-03-19 13:47 宇宙吾心 阅读(371) 评论(0) 推荐(0)

poj 3678

摘要: a AND b =1等价于(a || b) && (!a || b)&& (!b || a) =1a AND b =0等价于 !a || !b =1a OR b =0 等价于 !a AND !b=1等价于(!a || !b) && (!a || b)&& (!b || a) =1a OR b =1等价于 a || b =1a XOR b =1等价于(a || b) && (!a || !b) =1a XOR b =0 等价于 a XOR !b =1等价于(a || !b) && (!a || b) 阅读全文

posted @ 2011-03-19 12:53 宇宙吾心 阅读(482) 评论(0) 推荐(0)

poj 1330

摘要: 模板题。LCA(u){Make-Set(u)ancestor[Find-Set(u)]=u对于u的每一个孩子v{LCA(v)Union(u)ancestor[Find-Set(u)]=u}checked[u]=true对于每个(u,v)属于P{ifchecked[v]=truethen{回答u和v的最近公共祖先为ancestor[Find-Set(v)]}}} 代码:#include<iostream>#include<fstream>using namespace std;struct e{ int data; e *next;}edge[10001];int f[1 阅读全文

posted @ 2011-03-19 11:22 宇宙吾心 阅读(304) 评论(0) 推荐(0)

poj 3207

摘要: 2sat建好图就没问题。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int data; e *next;}edge[1001];int n,m;int a[501],b[501];int cmp(const void *a,const void *b){ return *(int *)a-*(int *)b;}int v[1001],low[1001],dfn[1001],stack[1001],scc[1001],tot,index,top;void tarjan(int s) 阅读全文

posted @ 2011-03-19 10:27 宇宙吾心 阅读(408) 评论(0) 推荐(0)

poj 2311

摘要: 注意如何转化为nim。代码:#include<iostream>#include<fstream>using namespace std;int g[201][201];int v[201][201];int n,m;int solve(int s,int t){ int i,j,k; if(v[s][t]) return g[s][t]; bool v2[400]={0}; v[s][t]=1; for(i=2;i<=s/2;i++) { j=solve(i,t); k=solve(s-i,t); v2[j^k]=1; } for(i=2;i<=t/2;i 阅读全文

posted @ 2011-03-19 09:35 宇宙吾心 阅读(459) 评论(0) 推荐(0)

上一页 1 ··· 26 27 28 29 30 31 32 33 34 ··· 36 下一页

导航