Problem   UVALive - 3211 - Now or later

Time Limit: 9000 mSec

Problem Description

Input

Output

Sample Input

10 44 156 153 182 48 109 160 201 55 186 54 207 55 165 17 58 132 160 87 197

Sample Output

10

题解:2-SAT问题板子题,这个问题主要是理论难度比较大,有了结论之后代码很容易,有专门的论文阐释算法的正确性,看了几位大佬写的,基本上明白是怎么一回事,理解不深刻,就不在这里胡扯了,直接上代码。

 #include <bits/stdc++.h>

 using namespace std;

 #define REP(i, n) for (int i = 1; i <= (n); i++)
#define sqr(x) ((x) * (x)) const int maxn = + ;
const int maxm = + ;
const int maxs = + ; typedef long long LL;
typedef pair<int, int> pii;
typedef pair<double, double> pdd; const LL unit = 1LL;
const int INF = 0x3f3f3f3f;
const LL mod = ;
const double eps = 1e-;
const double inf = 1e15;
const double pi = acos(-1.0); struct TwoSAT
{
int n;
vector<int> G[maxn * ];
bool mark[maxn * ];
int S[maxn * ], c; bool dfs(int x)
{
if (mark[x ^ ])
return false;
if (mark[x])
return true;
mark[x] = true;
S[c++] = x;
for (auto v : G[x])
{
if (!dfs(v))
return false;
}
return true;
} void init(int n)
{
this->n = n;
for (int i = ; i < n * ; i++)
{
G[i].clear();
}
memset(mark, , sizeof(mark));
} void add_clause(int x, int xval, int y, int yval)
{
x = x * + xval;
y = y * + yval;
G[x ^ ].push_back(y);
G[y ^ ].push_back(x);
} bool solve()
{
for (int i = ; i < n * ; i += )
{
if (!mark[i] && !mark[i + ])
{
c = ;
if (!dfs(i))
{
while (c > )
{
mark[S[--c]] = false;
}
if (!dfs(i + ))
return false;
}
}
}
return true;
}
}; TwoSAT solver; int n, T[maxn][]; bool Judge(int lim)
{
solver.init(n);
for (int i = ; i < n; i++)
{
for (int a = ; a < ; a++)
{
for (int j = i + ; j < n; j++)
{
for (int b = ; b < ; b++)
{
if (abs(T[i][a] - T[j][b]) < lim)
{
solver.add_clause(i, a ^ , j, b ^ );
}
}
}
}
}
return solver.solve();
} main()
{
ios::sync_with_stdio(false);
cin.tie();
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
while (cin >> n && n)
{
int le = , ri = ;
for (int i = ; i < n; i++)
{
for (int j = ; j < ; j++)
{
cin >> T[i][j];
ri = max(ri, T[i][j]);
}
} int ans = ;
while (le <= ri)
{
int mid = (le + ri) >> ;
if (Judge(mid))
{
ans = mid;
le = mid + ;
}
else
{
ri = mid - ;
}
}
cout << ans << endl;
}
return ;
}

UVALive - 3211 - Now or later(图论——2-SAT)的更多相关文章

  1. UVALive - 3211 (2-SAT + 二分)

    layout: post title: 训练指南 UVALive - 3211 (2-SAT + 二分) author: "luowentaoaa" catalog: true m ...

  2. UVALive 3211 Now or later

    每架飞机有早晚起降两种方式,给定n架飞机两种方式的起落时间,为每架飞机安排起落时间(早或晚),使得所有飞机起降时间按照早到晚的顺序之间的间隔时间最小值尽量大. 分析: 最小时间尽量大应该采用二分的方法 ...

  3. 2-sat基础题 uvalive 3211

    蓝书325页的基础题 二分+2-sat //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include <bits/stdc++.h> using n ...

  4. UVALive 3211 Now or later(2-sat)

    2-sat问题,一种在两种可能性中选择必然关系的问题. 推荐两篇论文,也是学2-sat公认比较好的材料.前者较好理解,后者需耐心看. http://www.google.com.hk/url?sa=t ...

  5. UVALive 3211 Now or later(2-SAT,二分,Kosaraju)

    题意: 有n个飞机要降落,每机都可以在两个时间点上选择降落.但是两机的降落时间间隔太小会影响安全性,所以,要求两机的降落时间应该达到最大,当然也不能冲突了.问最大的时间间隔是多少?(其实问的是max( ...

  6. 【UVALive - 3211】Now or later (二分+2-SAT)

    题意: 有n架飞机需要着陆.每架飞机有两种选择,早着陆或者晚着陆,二选其一.现在为了保证飞机的着陆安全,要求两架着陆的飞机的时间间隔的最小值达到最大. 分析: 最小值最大问题我们想到二分答案.对于猜测 ...

  7. 【二分答案+2-SAT】Now or later UVALive - 3211

    题目链接:https://cn.vjudge.net/contest/209473#problem/J 题目大意: 有n架飞机,每架飞机有两个可降落时间点a,b(a<b)(即一架飞机可以选择在时 ...

  8. Now or later UVALive - 3211(2-SAT 最小值最大化)

    emmm...去吃早饭了... rujia讲的很好.. 最小值最大化问题,,,二分枚举答案   设x1.x2为同一个集合中的元素,y1.y2为另一个集合中的元素,如果x1与y1之差小于mid,那么如果 ...

  9. UVALive - 3211 Now or later (二分+2SAT)

    题目链接 题意:有n架飞机,每架飞机有两个着陆时间点可以选,要求任意两架飞机的着陆时间之差不超过k,求k的最大值. 解法:由于每架飞机都有两个选择,并且必选且只能选其中一个,时间冲突也是发生在两架飞机 ...

随机推荐

  1. Error: Cannot fit requested classes in a single dex file (# methods: 149346 > 65536)

    引用第三方库的jar文件,都有可能会触发这个错误.解决方案如下: 参考<[Android]Cannot fit requested classes in a single dex file. T ...

  2. [Leetcode]538. Convert BST to Greater Tree

    Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original B ...

  3. 【Python3爬虫】微博用户爬虫

    此次爬虫要实现的是爬取某个微博用户的关注和粉丝的用户公开基本信息,包括用户昵称.id.性别.所在地和其粉丝数量,然后将爬取下来的数据保存在MongoDB数据库中,最后再生成几个图表来简单分析一下我们得 ...

  4. Typora - Markdown 语法说明

    Typora 是 Windows 下最好的 Markdown 编辑器!不接受反驳~ 导图 快捷键标题:Ctrl + 数字 Ctrl + 123456 代表 H1-H6 级标题Ctrl + 0 恢复普通 ...

  5. centos6.5-vsftp搭建

    我的机子是默认是没有的vsftp. yum install -y vsftp 创建账户专为ftp而生.useradd ftp01 更改账户不可登录系统.usermod -s /sbin/nologin ...

  6. xamarin.forms之使用CarouselView插件模仿网易新闻导航

    在APP中基本都能见到类似网易.今日头条等上边横向导航条,下边是左右滑动的页面,之前做iOS的时候模仿实现过,https://github.com/ywcui/ViewPagerndicator,在做 ...

  7. 第50章 设备授权端点(Device Authorization Endpoint) - Identity Server 4 中文文档(v1.0.0)

    设备授权端点可用于请求设备和用户代码.此端点用于启动设备流授权过程. 注意 终端会话端点的URL可通过发现端点获得. client_id 客户标识符(必填) client_secret 客户端密钥可以 ...

  8. Android开发过程中的坑及解决方法收录(六)

    1. file.listFiles 空指针异常 最近在弄个小项目,类似一个文件管理器,需要获得手机存储里的目录之后显示,但是运行过程中出现错误,搜索了资料,得出了以下的解决办法 问题产生的原因: an ...

  9. Java学习笔记之——集合

    集合是类,用来存储多个数据,有属性.方法 集合是一个可变数组,保存相同元素并且长度可变 1. 体系 (1)Collection:存储一个一个的值 Iterable: Iterable<T> ...

  10. Dynamics CRM项目实例之六:积分管理,汇总字段,计算字段,快速查看视图

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复137或者20141228可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me!        博文讲述的主要是如 ...