HDU - 1816 Get Luffy Out *(二分 + 2-SAT)
题目大意:有N串钥匙,M对锁。每串钥匙仅仅能选择当中一把。怎样选择,才干使开的锁达到最大(锁仅仅能按顺序一对一对开。仅仅要开了当中一个锁就可以)
解题思路:这题跟HDU - 3715 Go Deeper
这题的限制比較简单。都是二选一,2-SAT的裸题,仅仅只是加了二分而已
附上HDU - 3715 Go Deeper题解
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define N 4010
struct Pair{
int x, y;
}P[N];
int lock1[N], lock2[N], S[N];
bool mark[N];
int top, n, m;
vector<int> G[N];
void init() {
for (int i = 0; i < n; i++) {
scanf("%d%d", &P[i].x, &P[i].y);
}
for (int i = 1; i <= m; i++)
scanf("%d%d", &lock1[i], &lock2[i]);
}
void AddEdge(int x, int valx, int y, int valy) {
x = x * 2 + valx;
y = y * 2 + valy;
G[x ^ 1].push_back(y);
G[y ^ 1].push_back(x);
}
bool dfs(int u) {
if (mark[u ^ 1])
return false;
if (mark[u])
return true;
mark[u] = true;
S[++top] = u;
for (int i = 0; i < G[u].size(); i++)
if (!dfs(G[u][i]))
return false;
return true;
}
bool judge(int mid) {
for (int i = 0; i < 4 * n; i++)
G[i].clear();
for (int i = 0; i < n; i++)
AddEdge(P[i].x, 0, P[i].y, 0);
for (int i = 1; i <= mid; i++)
AddEdge(lock1[i], 1, lock2[i], 1);
memset(mark, 0, sizeof(mark));
for (int i = 0; i < 4 * n; i++) {
if (!mark[i] && !mark[i ^ 1]) {
top = 0;
if (!dfs(i)) {
while (top) mark[S[top--]] = false;
if (!dfs(i ^ 1))
return false;
}
}
}
return true;
}
void solve() {
int l = 1, r = m, mid;
while (l <= r) {
mid = (l + r) / 2;
if (judge(mid))
l = mid + 1;
else
r = mid - 1;
}
printf("%d\n", l - 1);
}
int main() {
while (scanf("%d%d", &n, &m) != EOF && n + m) {
init();
solve();
}
return 0;
}
HDU - 1816 Get Luffy Out *(二分 + 2-SAT)的更多相关文章
- HDU 1816 Get Luffy Out *
Get Luffy Out * Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- POJ 2723 HDU 1816 Get Luffy Out
二分答案 + 2-SAT验证 #include<cstdio> #include<cstring> #include<cmath> #include<stac ...
- HDU 1816, POJ 2723 Get Luffy Out(2-sat)
HDU 1816, POJ 2723 Get Luffy Out pid=1816" target="_blank" style="">题目链接 ...
- hdu 3433 A Task Process 二分+dp
A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 3622 Bomb Game(二分+2-SAT)
Bomb Game Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Get Luffy Out * HDU - 1816(2 - sat 妈的 智障)
题意: 英语限制了我的行动力....就是两个钥匙不能同时用,两个锁至少开一个 建个图 二分就好了...emm....dfs 开头low 写成sccno 然后生活失去希望... #include & ...
- hdu 1816(二分+2-sat)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1816 思路:首先将每把钥匙i拆成两个点i和i+2n,分别表示选与不选,对于被分成n对的钥匙,由于只能选 ...
- [BZOJ 1816][Cqoi2010]扑克牌(二分答案)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1816 分析: 我先以为是道水题,但是要注意的是每套牌中Joker只能用1张的,所以就出现了可能 ...
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- 利用 ildasm 修改被编译后DLL文件
在开发中遇到这样一个场景,需要修改一个dll文件(.NET程序集)中某些地方的类型名称,但没有源代码,只能修改IL代码. 操作步骤如下: 1. 运行ildasm ildasm是由微软提供的.NET程序 ...
- URAL 2062 Ambitious Experiment(分块)
[题目链接] http://acm.timus.ru/problem.aspx?space=1&num=2062 [题目大意] 给出两个操作,操作一给出区间[l,r],对l到r中的每一个下标i ...
- Java高级架构师(一)第07节:远程使用以及冲突解决
- Android UI Material Design
Material Design 中文版: http://wiki.jikexueyuan.com/project/material-design/ Material Design开发文章系列1:App ...
- activemq 5.13.2 jdbc 数据库持久化 异常 找不到驱动程序
原文:https://my.oschina.net/u/2284972/blog/662033 摘要: activemq jdbc 数据库持久化 异常 找不到驱动程序 Caused by: java. ...
- 【mybatis】mybatis执行一个update方法,返回值为1,但是数据库中数据并未更新,粘贴sql语句直接在数据库执行,等待好久报错:Lock wait timeout exceeded; try restarting transaction
今天使用mybatis和jpa的过程中,发现这样一个问题: mybatis执行一个update方法,返回值为1,但是数据库中数据并未更新,粘贴sql语句直接在数据库执行,等待好久报错:Lock wai ...
- RabbitMq_05_Topics
Topics (using the .NET client) Prerequisites This tutorial assumes RabbitMQ isinstalled and running ...
- Java几种常见的四舍五入的方法
/* * 在上面简单地介绍了银行家舍入法,目前java支持7中舍入法: 1. ROUND_UP:远离零方向舍入.向绝对值最大的方向舍入,只要舍弃位非0即进位. 2. ROUND_DOWN:趋向零方向舍 ...
- Xamarin.Forms+Prism(2)—— 基本使用 NavigationService 相对路径和绝对路径
本文主要对Prism框架下的导航服务NavigationService进行一次介绍和使用. 1.打开VS,可以看到左侧的已安装模版里面有: 2.创建完成后,从PCL项目中,看到App.xaml.cs中 ...
- http://blog.csdn.net/tkwxty/article/details/34474501
http://blog.csdn.net/tkwxty/article/details/34474501