- 博客(10)
- 资源 (1)
- 收藏
- 关注
原创 poj 3648 Wedding 2sat
2sat#include #include #include using namespace std;const int maxn=30*2+9;int n,m;int head[maxn];int lon;int dfn[maxn],low[maxn],stack[maxn],instack[maxn],s[maxn],un[maxn];int count,top,con;
2013-05-22 20:26:03 636
原创 poj 2723 Get Luffy Out 2sat
二分+2sat判可行性#include #include #include using namespace std;const int maxn=1024*2+9;int doorx[1<<12],doory[1<<12],x[maxn],y[maxn];int n,m;int dfn[maxn<<1],low[maxn<<1],stack[maxn<<1],instack[maxn
2013-05-21 22:46:38 663
原创 poj 3683 Priest John's Busiest Day 2-sat
经典2-sat问题,需要输出解#include #include #include using namespace std;const int maxn=2e3+9;int head[4][maxn],lon;int dfn[maxn],low[maxn],s[maxn],stack[maxn],instack[maxn];int que[maxn],in[maxn],to[
2013-05-21 13:33:32 839
原创 poj 2553 tarjan
求一个图出度为0的强连通分量。#include #include #include const int maxn=5500;using namespace std;struct{ int to,next;}e[maxn*maxn];int head[maxn],lon;void edgeini(){ memset(head,-1,sizeof(head));
2013-05-19 21:57:17 668
原创 poj 3177 Redundant Paths tarjan
在一个无向图中要增加几条边才能使得整个图成为双连通,对tarjan算法进行更改,求得去掉割边都的叶子节点的个数,这个数目要是为1,ans=0.否则,ans=(n+1)/2.#include #include #include using namespace std;const int maxn=5e3+9;struct{ int to,next;}e[maxn<<2];in
2013-05-19 21:50:39 736
原创 poj 3020 Antenna Placement 二分图匹配
黑白染色 然后求二分图最大匹配#include #include #include using namespace std;const int maxn=40+9;int n,m;char a[maxn][maxn];struct{ int to,next;}e[maxn*10*4];int head[maxn*10],lon;void edgeini(){
2013-05-18 16:00:50 740
原创 poj 1523 spf 求割点
无向图求割点的模版题。就是对tarjan的运用。#include #include #include using namespace std;const int maxn=1e3+9,N=1e3;bool e[maxn][maxn];int dfn[maxn],low[maxn],count,in[maxn];void tarjan(int t,int from){
2013-05-16 15:14:20 751
原创 poj 1470 Closest Common Ancestors
最近公共祖先的题目。第一个点不一定是跟。#include #include #include using namespace std;const int maxn=900+9;int head[maxn],lon,qhead[maxn],qlon;int ans[maxn],chk[maxn],f[maxn],in[maxn];struct node{
2013-05-08 21:20:38 721
原创 poj 3378 Crazy Thairs dp
用树状数组优化转移复杂度,结果会超long long,要用高精度。#include #include #include #include typedef unsigned long long ll;using namespace std;const int maxn=5e4+9;ll tree[6][maxn],dp[maxn][6];int a[maxn];int n;ty
2013-05-04 02:18:06 1013
原创 poj 3017 Cut the Sequence dp
dp[k]是非递增的,然后对于同样的转移代价,我们只需要找到i最小的dp[i]及可。 所以可以用单调队列维护一个递减的序列,存储转移代价,即一段中的最大值。对于每个转移代价下的dp[i]+a[j],把它压入set中。每次找到最小的值来更新dp[k]。 维护队列,set,有比较麻烦的边界条件,要好好处理。#include #include #include #
2013-05-03 18:03:50 788
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人