Poj3678:Katu Puzzle
大概题意
有\(n\)个数,可以为\(0/1\),给\(m\)个条件,表示某两个数经过\(or, and, xor\)后的数是多少
判断是否有解
Sol
\(2-SAT\)判定
建图
# include <iostream>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <math.h>
# include <algorithm>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(2005);
const int __(4e6 + 5);
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int n, m, first[_], cnt, num;
int S[_], vis[_], dfn[_], low[_], Index, col[_];
struct Edge{
int to, next;
} edge[__];
IL void Add(RG int u, RG int v){
edge[cnt] = (Edge){v, first[u]}; first[u] = cnt++;
}
IL void Tarjan(RG int u){
vis[u] = 1, dfn[u] = low[u] = ++Index, S[++S[0]] = u;
for(RG int e = first[u]; e != -1; e = edge[e].next){
RG int v = edge[e].to;
if(!dfn[v]) Tarjan(v), low[u] = min(low[u], low[v]);
else if(vis[v]) low[u] = min(low[u], dfn[v]);
}
if(dfn[u] != low[u]) return;
RG int v = S[S[0]--]; col[v] = ++num, vis[v] = 0;
while(v != u) v = S[S[0]--], col[v] = num, vis[v] = 0;
}
int main(RG int argc, RG char* argv[]){
Fill(first, -1), n = Input(), m = Input();
for(RG int i = 1; i <= m; ++i){
RG int u = Input() + 1, v = Input() + 1, w = Input();
RG char op; scanf(" %c", &op);
if(op == 'A'){
if(w) Add(u, v), Add(v, u), Add(u + n, u), Add(v + n, v);
else Add(u, v + n), Add(v, u + n);
}
else if(op == 'O'){
if(w) Add(u + n, v), Add(v + n, u);
else Add(u, u + n), Add(v, v + n), Add(u + n, v + n), Add(v + n, u + n);
}
else{
if(w) Add(u, v + n), Add(v, u + n), Add(u + n, v), Add(v + n, u);
else Add(u, v), Add(v, u), Add(u + n, v + n), Add(v + n, u + n);
}
}
for(RG int i = 1, tmp = n << 1; i <= tmp; ++i)
if(!dfn[i]) Tarjan(i);
for(RG int i = 1; i <= n; ++i)
if(col[i] == col[i + n]) return puts("NO"), 0;
return puts("YES"), 0;
}
Poj3678:Katu Puzzle的更多相关文章
- POJ3678:Katu Puzzle——题解
http://poj.org/problem?id=3678 总觉得这题比例题简单. 设a为x取0的点,a+n为x取1的点. 我们还是定义a到b表示取a必须取b. 那么我们有: 当AND: 1.当c= ...
- poj3678 Katu Puzzle 2-SAT
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6714 Accepted: 2472 Descr ...
- POJ3678 Katu Puzzle 【2-sat】
题目 Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a boolean ...
- 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 ...
- 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 ...
- POJ 3678 Katu Puzzle(2-SAT,合取范式大集合)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9987 Accepted: 3741 Descr ...
- POJ 3678 Katu Puzzle (2-SAT)
Katu Puzzle Time Limit: 1000MS ...
- POJ 3678 Katu Puzzle (经典2-Sat)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6553 Accepted: 2401 Descr ...
- 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 ...
随机推荐
- CocosCreator游戏开发---菜鸟学习之路(一)
PS(废话): 辞职后在家好久好久了,久到经济不允许了,接着就准备再次出去找工作了,然而工作哪有那么好找,特别是像我这种菜鸟.而且我还准备转行,准备去做游戏,技能等级接近于0,那工作就更难找了.既然如 ...
- System.in实现数据的键盘输入
System.in The "standard" input stream. This stream is already open and ready to supply inp ...
- Redmine基础: 邮件配置
1.用文本编辑器打开 D:\Bitnami\redmine-2.6.5-0\apps\redmine\htdocs\config\configuration.yml 文件,找到以下内容: 2.配置邮件 ...
- 在windows端和linux端安装Git
一.Git的安装 1. 在windows端 到地址:https://git-scm.com/downloads 选择对应版本下载后,进行傻瓜式安装即可 2. 在linux端 查看是否安装了git,出 ...
- 将Word表格中单元格中的文字替换成对应的图片
示例 原文件结构: 替换后文档结构: 软件截图: 代码: using System;using System.Collections.Generic;using System.ComponentMod ...
- Visual Studio 2017 Enterprise 发布 15.3.2 版,附离线安装包下载。
Visual Studio 2017 Enterprise 更新至 15.3.2 ,本安装包使用微软原版安装文件,配合layout指令全量下载后制作,内置中文语言包,包含 Visual Studio ...
- java-redis初探
一.Redis 简介 Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库. Redis 与其他 key - value 缓存产品有以下三个特点: Redis支持数据的 ...
- postman 中调试接口的小记录
1.form-data: 就是http请求中的multipart/form-data,它会将表单的数据处理为一条消息,以标签为单元,用分隔符分开.既可以上传键值对,也可以上传文件.当上传的字段是文件 ...
- R实战 第三篇:数据处理
在实际分析数据之前,必须对数据进行清理和转化,使数据符合相应的格式,提高数据的质量.数据处理通常包括增加新的变量.处理缺失值.类型转换.数据排序.数据集的合并和获取子集等. 一,增加新的变量 通常需要 ...
- ffmpeg结构体以及函数介绍(三)
1 AVPacket typedef struct AVPacket { /** * Presentation timestamp in AVStream->time_base units; t ...