博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Now or later UVALive - 3211(2-SAT 最小值最大化)
阅读量:4695 次
发布时间:2019-06-09

本文共 1464 字,大约阅读时间需要 4 分钟。

emmm。。。去吃早饭了。。。

rujia讲的很好。。

最小值最大化问题,,,二分枚举答案   设x1、x2为同一个集合中的元素,y1、y2为另一个集合中的元素,如果x1与y1之差小于mid,那么如果选了x1就必须选y2,反过来,选了y1就必须选x2。这样就是2-SAT模型了。只需找出使得这个2-SAT有解的最大mid即可。

 

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define rap(a, n) for(int i=a; i<=n; i++)#define MOD 2018#define LL long long#define ULL unsigned long long#define Pair pair
#define mem(a, b) memset(a, b, sizeof(a))#define _ ios_base::sync_with_stdio(0),cin.tie(0)//freopen("1.txt", "r", stdin);using namespace std;const int maxn = 10010, INF = 0x7fffffff;int n, T[maxn][2];struct TwoSAT{ int n; vector
G[maxn*2]; bool mark[maxn*2]; int S[maxn*2], c; 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; i < G[x].size(); i++) if(!dfs(G[x][i])) return false; return true; } void init(int n) { this->n = n; for(int i=0; i < n*2; i++) G[i].clear(); mem(mark, 0); } void add_clause(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); } bool solve() { for(int i=0; i < n*2; i+=2) { if(!mark[i] && !mark[i+1]) { c = 0; if(!dfs(i)) { while(c > 0) mark[S[--c]] = false; if(!dfs(i+1)) return false; } } } return true; }};TwoSAT solver;bool test(int diff){ solver.init(n); for(int i=0; i

 

转载于:https://www.cnblogs.com/WTSRUVF/p/9364865.html

你可能感兴趣的文章
u-boot启动第一阶段
查看>>
MySQL批量SQL插入性能优化
查看>>
定义列属性:null,default,PK,auto_increment
查看>>
用户画像展示
查看>>
C#中StreamReader读取中文出现乱码
查看>>
使用BufferedReader的时候出现的问题
查看>>
批处理文件中的路径问题
查看>>
hibernate出现No row with the given identifier exists问题
查看>>
为什么wait()和notify()属于Object类
查看>>
配置NRPE的通讯
查看>>
shp系列(一)——利用C++进行shp文件的读(打开)与写(创建)开言
查看>>
匹配两个空格之间的字符。。。
查看>>
CSS 文字溢出 变成省略号 ...
查看>>
Spring事务
查看>>
java编程基础(三)流程控制语句
查看>>
让数据库跑的更快的7个MySQL优化建议
查看>>
jquery 取id模糊查询
查看>>
解决在vue中,自用mask模态框出来后,下层的元素依旧可以滑动的问题
查看>>
修改node节点名称
查看>>
PAT(B) 1014 福尔摩斯的约会(Java)
查看>>