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

rujia讲的很好。。

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

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#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<int, int>
#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 = , INF = 0x7fffffff;
int n, T[maxn][]; 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(int i = ; i < G[x].size(); i++)
if(!dfs(G[x][i])) return false;
return true;
} void init(int n)
{
this->n = n;
for(int i=; i < n*; i++) G[i].clear();
mem(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; bool test(int diff)
{
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] )< diff) solver.add_clause(i, a^, j, b^);
return solver.solve();
} int main()
{
while(~scanf("%d", &n) && n)
{
int L = , R = ;
for(int i=; i<n; i++)
for(int a=; a<; a++)
{
scanf("%d", &T[i][a]);
R = max(R, T[i][a]);
}
while(L <= R)
{
int mid = L + (R-L)/;
if(test(mid)) L = mid + ;
else R = mid - ;
}
printf("%d\n", R); } return ;
}

Now or later UVALive - 3211(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(图论——2-SAT)

    Problem   UVALive - 3211 - Now or later Time Limit: 9000 mSec Problem Description Input Output Sampl ...

  3. POJ--3258 River Hopscotch (最小值最大化C++)

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15273   Accepted: 6465 ...

  4. Halum UVA - 11478(差分约束 + 二分最小值最大化)

    题意: 给定一个有向图,每条边都有一个权值,每次你可以选择一个结点v和一个整数d,把所有以v为终点的边的权值减小d,把所有以v为起点的边的权值增加d,最后要让所有边权的最小值非负且尽量大 两个特判 1 ...

  5. POJ-3258 (最小值最大化问题)

    POJ - 3258 River Hopscotch Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & ...

  6. UVALive 3211 Now or later

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

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

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

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

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

  9. 2-sat基础题 uvalive 3211

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

随机推荐

  1. 【LG3233】[HNOI2014]世界树

    题面 洛谷 题解 代码 #include <iostream> #include <cstdio> #include <cstdlib> #include < ...

  2. 【LG4148】简单题

    [LG4148]简单题 题面 洛谷 题解 \(kdt\)模板题呀... #include <iostream> #include <cstdio> #include <c ...

  3. 后端API入门到放弃指北

    后端API入门学习指北 了解一下一下概念. RESTful API标准] 所有的API都遵循[RESTful API标准]. 建议大家都简单了解一下HTTP协议和RESTful API相关资料. 阮一 ...

  4. MySQLdb in Python: “Can't connect to MySQL server on 'localhost'”

    因为我使用的是win64,所以在此系统下,需要设置为 127.0.0.1 #coding=utf-8 import MySQLdb if __name__ == '__main__': # 打开数据库 ...

  5. 【excle基础】如何去掉excel某一列中的字段的空格

    如图所示,想要去掉A列的空格: 查找空格,全部替换

  6. DB知识点记录

    DB知识点记录 分页 SqlServer:ROW_NUMBER () over (ORDER BY ID) AS RN, MySql:limit Oracle:ROWNUM AS RN 数据表的基本结 ...

  7. 如何使用phpredis连接Redis的方法

    本文跟大家介绍使用同一VPC内弹性云服务器ECS上的phpredis连接Redis的方法. 更多的客户端的使用方法,请参考https://redis.io/clients 前提条件 已成功申请Redi ...

  8. springmvc 静态资源 配置

    SpringMVC提供<mvc:resources>来设置静态资源,但是增加该设置如果采用通配符的方式增加拦截器的话仍然会被拦截器拦截,可采用如下方案进行解决: 方案一.拦截器中增加针对静 ...

  9. Python--matplotlib 绘图可视化练手--折线图/条形图

    最近学习matplotlib绘图可视化,感觉知识点比较多,边学习边记录. 对于数据可视化,个人建议Jupyter Notebook. 1.首先导包,设置环境 import pandas as pd i ...

  10. Beta冲刺第二周王者荣耀交流协会第四次会议

    1.例会照片: 成员:王超,高远博,冉华,王磊,王玉玲,任思佳,袁玥全部到齐. master:王玉玲 2.时间跨度: 2017年11月20日 18:00 — 18:13,总计13分钟. 3.地点: 一 ...