题意:

  有n个未知量,m对未知量之间的关系,判断是否能求出所有的未知量且满足这些关系

解析:

  关系建边就好了

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define pd(a) printf("%d\n", a);
#define plld(a) printf("%lld\n", a);
#define pc(a) printf("%c\n", a);
#define ps(a) printf("%s\n", a);
#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 = 1e6 + , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
int n, m;
vector<int> G[maxn << ];
int sccno[maxn], vis[maxn], low[maxn], scc_cnt, scc_clock;
stack<int> S;
void init()
{
mem(vis, );
mem(low, );
mem(sccno, );
scc_cnt = scc_clock = ;
for(int i = ; i < maxn; i++) G[i].clear();
} void dfs(int u)
{
low[u] = vis[u] = ++scc_clock;
S.push(u);
for(int i = ; i < G[u].size(); i++)
{
int v = G[u][i];
if(!vis[v])
{
dfs(v);
low[u] = min(low[u], low[v]);
}
else if(!sccno[v])
low[u] = min(low[u], vis[v]);
}
if(low[u] == vis[u])
{
scc_cnt++;
for(;;)
{
int x = S.top(); S.pop();
sccno[x] = scc_cnt;
if(x == u) break;
}
}
} bool check()
{
for(int i = ; i < n * ; i+=)
if(sccno[i] == sccno[i + ])
return false;
return true;
} int main()
{
init();
int a, b, c;
char op[];
rd(n), rd(m);
for(int i = ; i < m; i++)
{
rd(a), rd(b), rd(c), rs(op);
if(op[] == 'A')
{
if(c)
{
G[a << | ].push_back(b << | );
G[b << | ].push_back(a << | );
G[a << ].push_back(a << | );
G[b << ].push_back(b << | );
}
else
{
G[a << | ].push_back(b << );
G[b << | ].push_back(a << );
}
}
else if(op[] == 'O')
{
if(c)
{
G[a << ].push_back(b << | );
G[b << ].push_back(a << | );
}
else
{
G[a << ].push_back(b << );
G[b << ].push_back(a << );
G[a << | ].push_back(a << );
G[b << | ].push_back(b << );
}
}
else if(op[] == 'X')
{
if(c)
{
G[a << | ].push_back(b << );
G[b << ].push_back(a << | );
G[a << ].push_back(b << | );
G[b << | ].push_back(a << );
}
else
{
G[a << ].push_back(b << );
G[b << ].push_back(a << );
G[a << | ].push_back(b << | );
G[b << | ].push_back(a << | );
}
}
}
for(int i = ; i < n * ; i++)
if(!vis[i]) dfs(i);
if(check()) puts("YES");
else puts("NO"); return ;
}

Katu Puzzle POJ - 3678(水2 - sat)的更多相关文章

  1. Katu Puzzle POJ - 3678 (2 - sat)

    有N个变量X1X1~XNXN,每个变量的可能取值为0或1. 给定M个算式,每个算式形如 XaopXb=cXaopXb=c,其中 a,b 是变量编号,c 是数字0或1,op 是 and,or,xor 三 ...

  2. Ikki's Story IV - Panda's Trick POJ - 3207(水2 - sat 在圈内 还是 在圈外)

    题意: 就是一个圈上有n个点,给出m对个点,这m对个点,每一对都有一条边,合理安排这些边在圈内或圈外,能否不相交 解析: 我手残 我手残 我手残 写一下情况 只能是一个在圈外 一个在圈内 即一个1一个 ...

  3. POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang

    Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...

  4. POJ 3678 Katu Puzzle(2-SAT,合取范式大集合)

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9987   Accepted: 3741 Descr ...

  5. poj 3678 Katu Puzzle(2-sat)

    Description Katu Puzzle ≤ c ≤ ). One Katu ≤ Xi ≤ ) such that for each edge e(a, b) labeled by op and ...

  6. POJ 3678 Katu Puzzle (经典2-Sat)

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6553   Accepted: 2401 Descr ...

  7. POJ 3678 Katu Puzzle (2-SAT)

                                                                         Katu Puzzle Time Limit: 1000MS ...

  8. poj 3678 Katu Puzzle 2-SAT 建图入门

    Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...

  9. poj3678 Katu Puzzle 2-SAT

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6714   Accepted: 2472 Descr ...

随机推荐

  1. 关于 HTTP GET/POST 请求参数长度最大值的一个理解误区(转载)

    1. Get方法长度限制 Http Get方法提交的数据大小长度并没有限制,HTTP协议规范没有对URL长度进行限制.这个限制是特定的浏览器及服务器对它的限制.下面就是对各种浏览器和服务器的最大处理能 ...

  2. socketserver + ftp

    --------------------------------------------生活不止眼前的苟且,还有诗和远方的田野. day 29 socketserver + ftp # # ----- ...

  3. hdu 1730 Nim博弈

    题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1730 Nim博弈为:n堆石子,每个人可以在任意一堆中取任意数量的石子 n个数异或值为0就后手赢,否则先 ...

  4. Problem 2285 迷宫寻宝

    http://acm.fzu.edu.cn/problem.php?pid=2285 Problem Description 洪尼玛今天准备去寻宝,在一个n*n (n行, n列)的迷宫中,存在着一个入 ...

  5. CentOS云厂商清单

    Download CentOShttps://www.centos.org/download/ Download - CentOS Wikihttps://wiki.centos.org/Downlo ...

  6. 原生node路由操作以及注意事项

    var http = require("http"); var url = require("url"); var ejs = require("ej ...

  7. Json详解以及fastjson使用教程

    Json是一种轻量级的数据交换格式,采用一种“键:值”对的文本格式来存储和表示数据,在系统交换数据过程中常常被使用,是一种理想的数据交换语言.在使用Java做Web开发时,不可避免的会遇到Json的使 ...

  8. Mybatis测试用例

    package cn.zhangxueliang.mybatis.mapper; import static org.junit.Assert.*; import java.io.InputStrea ...

  9. .Net中EF通用数据层小结

    增删改查: using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; u ...

  10. leetcode资料整理

    注:借鉴了 http://m.blog.csdn.net/blog/lsg32/18712353 在Github上提供leetcode有: 1.https://github.com/soulmachi ...