把每对钥匙看做一个变量,那两个钥匙看做他的两个状态

每一个开门的要求就是一个条件(xi or xj)

很显然有了2sat的基本要素

2sat是一个判定性问题,而这题求最多能过几个门;

不难想到二分答案,转化为判定性问题可轻松解决

 type node=record
       next,point:longint;
     end;
var edge:array[..] of node;
    v,f:array[..] of boolean;
    other,d1,d2,be,dfn,low,p,st:array[..] of longint;
    mid,l,r,n,m,x,y,ans,len,sum,t,h,i:longint; function min(a,b:longint):longint;
  begin
    if a>b then exit(b) else exit(a);
  end; procedure add(x,y:longint);
  begin
    inc(len);
    edge[len].point:=y;
    edge[len].next:=p[x];
    p[x]:=len;
  end; procedure tarjan(x:longint);
  var i,y:longint;
  begin
    inc(h);
    inc(t);
    st[t]:=x;
    dfn[x]:=h;
    low[x]:=h;
    f[x]:=true;
    v[x]:=true;
    i:=p[x];
    while i<>- do
    begin
      y:=edge[i].point;
      if not v[y] then
      begin
        tarjan(y);
        low[x]:=min(low[x],low[y]);
      end
      else if f[y] then low[x]:=min(low[x],low[y]);
      i:=edge[i].next;
    end;
    if low[x]=dfn[x] then
    begin
      inc(sum);
      while st[t+]<>x do
      begin
        y:=st[t];
        f[y]:=false;
        be[y]:=sum;
        dec(t);
      end;
    end;
  end; function check(k:longint):boolean;
  var i,x,y:longint;
  begin
    len:=;
    fillchar(p,sizeof(p),);
    fillchar(v,sizeof(v),false);
    fillchar(f,sizeof(f),false);
    fillchar(st,sizeof(st),);
    fillchar(be,sizeof(be),);
    sum:=;
    for i:= to k do
    begin
      x:=d1[i];
      y:=d2[i];
      add(other[x],y);
      add(other[y],x);
    end;
    for i:= to *n- do
      if not v[i] then
      begin
        t:=;
        h:=;
        tarjan(i);
      end;

    for i:= to *n- do
      if be[other[i]]=be[i] then exit(false);
    exit(true);
  end; begin
  readln(n,m);
  while (n<>) and (m<>) do
  begin
    len:=;
    fillchar(p,sizeof(p),);
    for i:= to n do
    begin
      readln(x,y);
      other[x]:=y;
      other[y]:=x;
    end;
    for i:= to m do
      readln(d1[i],d2[i]);
    ans:=;
    l:=;
    r:=m;
    while l<=r do
    begin
      mid:=(l+r) shr ;
      if check(mid) then
      begin
        ans:=mid;
        l:=mid+;
      end
      else r:=mid-;
    end;
    writeln(ans);
    readln(n,m);
  end;
end.

poj2723的更多相关文章

  1. hdu3715 Go Deeper[二分+2-SAT]/poj2723 Get Luffy Out[二分+2-SAT]

    这题转化一下题意就是给一堆形如$a_i + a_j \ne c\quad (a_i\in [0,1],c\in [0,2])$的限制,问从开头开始最多到哪条限制全是有解的. 那么,首先有可二分性,所以 ...

  2. 【POJ2723】Get Luffy Out - 二分+2-SAT

    题面描述 Ratish is a young man who always dreams of being a hero. One day his friend Luffy was caught by ...

  3. Poj2723:Get Luffy Out

    题意 给出 n 对钥匙,每对只能挑一把使用,每把只能用一次,当一对钥匙中的一把被使用后,另一把也就不能再用了:然后给出 m 道门,每个门都有两把钥匙可以打开,问最多能开几道门(按给出的顺序开). So ...

  4. poj2723 2-sat

    当两个门锁相同时,这个钥匙必须用,不同时分开用 可以直接遍历门,当然二分更快 #include<map> #include<set> #include<cmath> ...

  5. POJ2723 Get Luffy Out 【2-sat】

    题目 Ratish is a young man who always dreams of being a hero. One day his friend Luffy was caught by P ...

  6. poj2723 2sat判断解+二分

    典型的2-sat问题,题意:有m个门,每个门上俩把锁,开启其中一把即可,现在给n对钥匙(所有 钥匙编号0123456...2n-1),每对钥匙只能用一把,要求尽可能开门多(按顺序,前max个). 关键 ...

  7. POJ2723 Get Luffy Out解题报告tarjan+2-SAT+二分

    今天看到讲2-SAT比较好的blog,感觉微微的理解了2-SAT 传送门 参考: https://blog.csdn.net/leolin_/article/details/6680144 题意:你有 ...

  8. POJ2723 题解

    WA了半天才发现居然是因为没看见这道题有多组数据,wzfl... 题目大意:有N对钥匙,对于每一对钥匙,如果使用了其中一把,另一把钥匙就会消失.接下来有M扇门,每扇门上有两把锁,分别对应两把钥匙(锁会 ...

  9. ACM训练计划step 2 [非原创]

    (Step2-500题)POJ训练计划+SGU 经过Step1-500题训练,接下来可以开始Step2-500题,包括POJ训练计划的298题和SGU前两章200题.需要1-1年半时间继续提高解决问题 ...

随机推荐

  1. 13_ServletContext对象

    [简介] ServletContext即Servlet上下文对象,该对象表示当前的web应用环境信息,一个Web应用只会创建一个ServletContext对象. Web容器启动的时候,它会为每个We ...

  2. springmvc(六)——视图和视图解析器

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoIAAAGrCAIAAADb2WEhAAAgAElEQVR4nOzdaVhTd78vfF8/z772c9 ...

  3. OpenJudge 2738 浮点数加法

    1.链接地址: http://bailian.openjudge.cn/practice/2738 2.题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 求2个浮点数相加的和 题目 ...

  4. ubuntu12修改ulimit

    第一步:配置/etc/security/limits.confsudo vim /etc/security/limits.conf文件尾追加 * hard nofile 40960* soft nof ...

  5. C#基础(五)——类中私有构造函数作用

    如果类成员有private修饰符,就不允许在类范围以外访问这个类成员.对类构造函数应用private修饰符时,则禁止外部类创建该类的实例.尽管看上去有些不好理解(既然不能实例化,那么这个类还有什么用处 ...

  6. shell脚本加不加export的区别

    加了export: jackyyu@ubuntu:~$ cat 1.sh #!/bin/dash test=test echo ${test} echo ${TERM} TERM=dumb expor ...

  7. django 中的延迟加载技术,python中的lazy技术

    ---恢复内容开始--- 说起lazy_object,首先想到的是django orm中的query_set.fn.Stream这两个类. query_set只在需要数据库中的数据的时候才 产生db ...

  8. ubuntu10.04搭建嵌入式开发环境

    改源 配置vim set number set autoindent set smartindent set tabstop=4 set incsearch 安装g++ 配置samba 1.先安装程序 ...

  9. 树莓派 raspberry 入门之安装操作系统以及配置

    最近新入手一树莓派,型号是2代B,屏幕是微雪的7 inch c型 显示屏.下面来教大家怎么点亮树莓派. 第一步,装好显示器,显示器的电源接在树莓派的usb口上,HDMI口不多说,连上.然后装好鼠标.键 ...

  10. Hive优化(转)

    一.join优化 Join查找操作的基本原则:应该将条目少的表/子查询放在 Join 操作符的左边.原因是在 Join 操作的 Reduce 阶段,位于 Join 操作符左边的表的内容会被加载进内存, ...