首页 > Web开发 > 详细

BZOJ 1823: [JSOI2010]满汉全席 [2-SAT]

时间:2017-02-22 13:30:45      阅读:159      评论:0      收藏:0      [点我收藏+]

http://www.lydsy.com/JudgeOnline/problem.php?id=1823

题意:每种菜满汉两种做法,一个选手一种菜只能选一种做法,一个评委指定了两种菜及做法,必须有一种满足才行;问是否存在满足所有评委的方案


裸题......一种菜两种选择.....对一个评委来说不选一种则必须选另一种

$Candy?$这个沙茶把$m$当$n$用$WA$了好几次

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=405,M=2005;
typedef long long ll;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<0||c>9){if(c==-)f=-1;c=getchar();}
    while(c>=0&&c<=9){x=x*10+c-0;c=getchar();}
    return x*f;
}
inline void get(int &x,char &c){
    c=getchar();
    while(c!=h&&c!=m) c=getchar();
    x=read()<<1;
}
int n,m,x,y;
char cx,cy;
struct edge{
    int v,ne;
}e[M];
int h[N],cnt=0;
inline void ins(int u,int v){
    cnt++;
    e[cnt].v=v;e[cnt].ne=h[u];h[u]=cnt;
}
int dfn[N],low[N],dfc,belong[N],scc;
int st[N],top;
void dfs(int u){
    dfn[u]=low[u]=++dfc;
    st[++top]=u;
    for(int i=h[u];i;i=e[i].ne){
        int v=e[i].v;
        if(!dfn[v]){
            dfs(v);
            low[u]=min(low[u],low[v]);
        }else if(!belong[v])
            low[u]=min(low[u],dfn[v]);
    }
    if(dfn[u]==low[u]){
        scc++;int x=0;
        while(x!=u){
            x=st[top--];
            belong[x]=scc;
        }
    }
}
bool judge(){
    for(int i=1;i<=n;i++) if(belong[(i<<1)-1]==belong[i<<1]) return false;
    return true;
}
int main(){
    freopen("in","r",stdin);
    int T=read();
    while(T--){
        cnt=0;memset(h,0,sizeof(h));
        n=read();m=read();
        for(int i=1;i<=m;i++){
            get(x,cx);get(y,cy);//m 2i-1 ; h 2i
            if(cx==m){
                if(cy==m) ins(x,y-1),ins(y,x-1);
                if(cy==h) ins(x,y),ins(y-1,x-1);
            }
            if(cx==h){
                if(cy==m) ins(x-1,y-1),ins(y,x);
                if(cy==h) ins(x-1,y),ins(y-1,x);
            }
        }
        int _=n<<1;
        for(int i=1;i<=_;i++) dfn[i]=low[i]=belong[i]=0;
        for(int i=1;i<=_;i++) if(!dfn[i]) dfs(i);
        if(judge()) puts("GOOD");
        else puts("BAD");
    }
}

 

BZOJ 1823: [JSOI2010]满汉全席 [2-SAT]

原文:http://www.cnblogs.com/candy99/p/6427941.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!