UVA Live 3211飞机调度问题-二分+2-SAT

本文详细解析了一道经典的2-SAT问题,通过提供作者的C++代码实现,展示了如何在9000ms的时间限制下高效解决该问题。重点在于理解2-SAT算法及其在实际编程中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目大家自己找吧,最近好像什么连接都粘不了,将就着看吧。。


这题不分析,太经典了,具体看白书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])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值