【POJ】3678 Katu Puzzle
http://poj.org/problem?id=3678
题意:很幼稚的题目直接看英文题面= =
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
const int N=1000*2+10, M=N*N*4;
struct E { int next, to; }e[M];
int ihead[N], cnt, tot, num, vis[N], FF[N], LL[N], p[N], n, m, top, s[N];
void add(int u, int v) { e[++cnt]=(E){ihead[u], v}; ihead[u]=cnt; }
void tarjan(int x) {
FF[x]=LL[x]=++tot; vis[x]=1; s[++top]=x;
for(int i=ihead[x]; i; i=e[i].next) {
if(!FF[e[i].to]) tarjan(e[i].to), LL[x]=min(LL[x], LL[e[i].to]);
else if(vis[e[i].to]) LL[x]=min(LL[x], FF[e[i].to]);
}
if(FF[x]==LL[x]) {
int y;
++num;
do {
y=s[top--];
vis[y]=0;
p[y]=num;
} while(x!=y);
}
}
void clr() {
cnt=tot=num=top=0;
int nn=n<<1;
memset(ihead, 0, sizeof(int)*(nn));
memset(p, 0, sizeof(int)*(nn));
memset(FF, 0, sizeof(int)*(nn));
}
bool check() {
int nn=n<<1, flag=1;
for(int i=0; i<nn; ++i) if(!FF[i]) tarjan(i);
for(int i=0; i<nn; i+=2) if(p[i]==p[i|1]) { flag=0; break; }
clr();
return flag;
}
int main() {
while(~scanf("%d%d", &n, &m)) {
for(int i=0; i<m; ++i) {
int a, b, c; static char s[5];
scanf("%d%d%d%s", &a, &b, &c, s);
a<<=1; b<<=1;
if(s[0]=='A') {
if(c) add(a^1, a), add(b^1, b);
else add(a, b^1), add(b, a^1);
}
else if(s[0]=='O') {
if(c) add(a^1, b), add(b^1, a);
else add(a, a^1), add(b, b^1);
}
else {
if(c) add(a^1, b), add(b^1, a), add(a, b^1), add(b, a^1);
else add(a, b), add(a^1, b^1), add(b, a), add(b^1, a^1);
}
}
check()?puts("YES"):puts("NO");
}
return 0;
}
随便搞搞就行啦= =
【POJ】3678 Katu Puzzle的更多相关文章
- 【POJ】1704 Georgia and Bob(Staircase Nim)
Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...
- 【POJ】1067 取石子游戏(博弈论)
Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...
- 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)
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)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6553 Accepted: 2401 Descr ...
- 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 ...
- 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 ...
- 【POJ】1222 EXTENDED LIGHTS OUT
[算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...
随机推荐
- Shell编程基础教程4--控制流结构
4.控制流结构 4.1.控制结构 4.2.if then else语句 格式: if 条件1 //如果条件1为真 then 命令1 //那么,执行命令1 el ...
- WCF消息拦截,利用消息拦截做身份验证服务
本文参考 http://blog.csdn.net/tcjiaan/article/details/8274493 博客而写 添加对信息处理的类 /// <summary> /// 消 ...
- android 入门-引用库项目
http://blog.csdn.net/arui319/article/details/6831164
- IIS 内部运行机制
ASP.NET是一个非常强大的构建Web应用的平台,它提供了极大的灵活性和能力以致于可以用它来构建所有类型的Web应用. 绝大多数的人只熟悉高层的框架如: WebForms 和 WebServices ...
- matlab练习程序(Sepia Tone滤镜)
我手机上有一个软件实现了很多图像滤镜,挺有意思,我打算都尝试一下. 这个滤镜主要是实现老照片效果. 代码很短,我就不详细介绍了. 原图: 处理后效果: matlab代码如下: clear all;cl ...
- C语言中运算符的口决
- Socket编程基础知识
端口号常识: 端口号被从1 开始分配. 通常端口号超出255 的部分被本地主机保留为私有用途. 1到255 之间的号码被用于远程应用程序所请求的进程和网络服务. 每个网络通信循环地 ...
- kafka producer源码
producer接口: /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor l ...
- AndroidManifest.xml权限大全
本文转 https://my.oschina.net/duwaiweb/blog/75935 问登记属性 android.permission.ACCESS_CHECKIN_PROPERTIES , ...
- 宫格布局实例(注意jquery的版本号要统一)2
<!DOCTYPE html><html><head><meta charset="utf-8" /><style> * ...