HDU 1816 Get Luffy Out *
Get Luffy Out *
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 570 Accepted Submission(s): 225
Behind the large door, there is a nesting prison, which consists of M floors. Each floor except the deepest one has a door leading to the next floor, and there are two locks in each of these doors. Ratish can pass through a door if he opens either of the two locks in it. There are 2N different types of locks in all. The same type of locks may appear in different doors, and a door may have two locks of the same type. There is only one key that can unlock one type of lock, so there are 2N keys for all the 2N types of locks. These 2N keys were made N pairs,one key may be appear in some pairs, and once one key in a pair is used, the other key will disappear and never show up again.
Later, Ratish found N pairs of keys under the rock and a piece of paper recording exactly what kinds of locks are in the M doors. But Ratish doesn't know which floor Luffy is held, so he has to open as many doors as possible. Can you help him to choose N keys to open the maximum number of doors?
0 3
1 2
4 5
0 1
0 2
4 1
4 2
3 5
2 2
0 0
题目有更改!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
using namespace std;
const int N = (<<); int n , m , st[N<<] ,top;
int eh[N] , et[N*N] , nxt[N*N] , tot ;
bool mark[N<<]; struct node
{
int x , y ;
} key[N<<] , door[N<<]; void init()
{
tot = ;
memset( eh , - , sizeof eh );
memset( mark ,false , sizeof mark );
} void addedge( int u , int v )
{
et[tot] = v , nxt[tot] = eh[u] , eh[u] = tot++ ;
et[tot] = u , nxt[tot] = eh[v] , eh[v] = tot++ ;
} bool dfs( int u )
{
if( mark[u] ) return true;
if( mark[u^] ) return false ;
mark[u] = true ;
st[top++] = u ;
for( int i = eh[u] ; ~i ; i = nxt[i] ){
int v = et[i];
if( !dfs(v^) ) return false;
}
return true;
} bool solve()
{
for( int i = ; i < * n ; i += ){
if( !mark[i] && !mark[i+] ){
top = ;
if( !dfs(i) ){
while( top > ) mark[ st[--top] ] = false ;
if( !dfs(i+) ) return false;
}
}
}
return true;
} bool test( int dep )
{
init();
for( int i = ; i < n ; ++i ){
addedge( *key[i].x , *key[i].y );
}
for( int i = ; i < dep ; ++i ){
addedge(*door[i].x^,*door[i].y^);
}
return solve();
} void run()
{
int x , y ;
// cout << N <<endl;
for( int i = ; i < n ; ++i ){
scanf("%d%d",&key[i].x,&key[i].y);
} for( int i = ; i < m ; ++i ){
scanf("%d%d",&door[i].x,&door[i].y);
} int l = , r = m , ans = ;
while( l <= r )
{
int mid = ( l+r )>>;
if( test(mid) ) ans = mid , l = mid + ;
else r = mid - ;
}
printf("%d\n",ans);
} int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
while( scanf("%d%d",&n,&m) ){
if( !n && !m ) break;
run();
}
}
HDU 1816 Get Luffy Out *的更多相关文章
- HDU - 1816 Get Luffy Out *(二分 + 2-SAT)
题目大意:有N串钥匙,M对锁.每串钥匙仅仅能选择当中一把.怎样选择,才干使开的锁达到最大(锁仅仅能按顺序一对一对开.仅仅要开了当中一个锁就可以) 解题思路:这题跟HDU - 3715 Go Deepe ...
- 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="">题目链接 ...
- 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对的钥匙,由于只能选 ...
- 【图论】2-sat总结
2-sat总结 2-sat问题,一般表现的形式为.每一个点有两种方式a,b,要么选a,要么选b.而且点点之间有一些约束关系.比如:u和v至少一个选a.那么这就是一个表达式.把a当成真,b当成假,那就是 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
随机推荐
- js中的对象类型的基本操作
示例 /** * 对象属于一种复合数据类型,在对象中可以保存多个不同数据类型的属性 * 对象的分类: * 1.内建对象 * - 由ES标准定义的对象,在任何ES的实现中都可以使用,比如:Math, * ...
- elasticsearch 深入 —— Scroll滚动查询
Scroll search 请求返回一个单一的结果"页",而 scroll API 可以被用来检索大量的结果(甚至所有的结果),就像在传统数据库中使用的游标 cursor. 滚动并 ...
- vue项目build打包后图片路径不对导致图片空白不显示问题解决方法
1.在上篇文章src配置及引入的基础上修改项目配置: 文章链接地址:https://www.cnblogs.com/hsl-shiliang/p/10333022.html. 2.具体配置过程如图: ...
- 《x的奇幻之旅》:有趣的数学科普
本书是相对比较少见的数学方面的科普书.从最简单的阿拉伯数字.加减法,一直到概率统计.微积分.群论.拓扑.微分几何,每个主题都用几千字做一些深入浅出的介绍.写的相当的有趣. 在书中又一次看到这个有趣的事 ...
- Sass函数:数学函数-abs函数
abs( ) 函数会返回一个数的绝对值. >> abs(10) 10 >> abs(-10) 10 >> abs(-10px) 10px >> abs( ...
- Sass-除法
Sass的乘法运算规则也适用于除法运算.不过除了除法运算还有一个特殊之处.众所周知“/”符号在css中已作为一种符号使用,因此在sass中做除法运算时,直接使用"/" 符号作为除号 ...
- procixx地址
\\192.168.35.7\Download\Builds\procixx_psoc
- JS中的一些遍历方法
1.遍历数组 以下遍历方法中for循环性能最好,而且优化版for循环性能最高.只有forEach不能跳出循环. 在循环数组时,如果在循环过程中对数组进行了增删改,那么在后面的每次循环中,进行操作的都是 ...
- [CF1168D]Anagram Paths
题意:给一棵\(n\)个节点的二叉树,每条边上有一个小写字母或者\(?\),\(q\)次修改操作,每次修改某条边上的字符,问修改后是否存在一种方案,使得给所有\(?\)填上小写字母后,所有叶子到根的路 ...
- 线性规划(Simplex单纯形)与对偶问题
线性规划 首先一般所有的线性规划问题我们都可以转换成如下标准型: 但是我们可以发现上面都是不等式,而我们计算中更希望是等式,所以我们引入这个新的概念:松弛型: 很显然我们最后要求是所有的约束左边的变量 ...