题目大家自己找吧,最近好像什么连接都粘不了,将就着看吧。。
这题不分析,太经典了,具体看白书Page 326页吧。。899ms,暴力其实也好快,时限是9000ms。。
/****************************
* author:crazy_石头
* date:2014/04/25
* time:899 ms
* algorithm:2-SAT
* Pro:UVA Live 3211
***************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define INF INT_MAX
#define eps 1e-8
#define A system("pause")
#define rep(i,h,n) for(int i=(h);i<=(n);i++)
#define ms(a,b) memset((a),(b),sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const int maxn=2000+5;
const int maxm=30;
struct TwoSAT
{
int n;
vectorg[maxn<<1];
bool mark[maxn<<1];
int s[maxn<<1],c;
inline bool dfs(int x)
{
if(mark[x^1]) return false;
if(mark[x]) return true;
mark[x]=true;
s[c++]=x;//入栈;
for(int i=0;in=n;
rep(i,0,n*2-1) g[i].clear();
ms(mark,0);
}
inline void add(int x,int xval,int y,int yval)
{
x=x*2+xval;
y=y*2+yval;
g[x^1].push_back(y);
g[y^1].push_back(x);
}
inline bool solve()
{
for(int i=0;i0)mark[s[--c]]=false;
if(!dfs(i^1)) return false;
}
}
}
return true;
}
};
TwoSAT solver;
int n,T[maxn][2];
inline bool test(int diff)
{
solver.init(n);
rep(i,0,n-1) rep(a,0,1) rep(j,i+1,n-1) rep(b,0,1)
if(abs(T[i][a]-T[j][b])