【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为真.与 ...
随机推荐
- SQL中的JOIN类型解释(CROSS, INNER,OUTER),关键字ON,USING
书上讲得明白,解了不少迷惑. SELECT e.fname, e.lname, d.name FROM employee AS e INNER JOIN department AS d ON e.de ...
- Oralce sysaux WRH$_ACTIVE_SESSION_HISTORY清理
In this Document Symptoms Cause Solution References Symptoms sysaux表空間的WRH$_ACTIVE_SESSION_HISTORY表變 ...
- ZooKeeper 的羊群效应
一个需要避免的问题是当一个特定的znode 改变的时候ZooKeper 触发了所有watches 的事件. 举个例子,如果有1000个客户端watch 一个znode的exists调用,当这个节点被创 ...
- iOS和Android的app界面设计规范(转)
记录一下iOS和Andoird的界面设计规范,方便进行标准的产品设计,并与设计师顺畅沟通 iOS篇 界面尺寸 设备 分辨率 状态栏高度 导航栏高度 标签栏高度 iPhone6 plus 1242×22 ...
- Android LayoutInflater详解 (转)
在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例 ...
- JAVA安装,环境变量配置
JAVA环境变量设置 PATH %JAVA_HOME%\bin JAVA_HOME D:\ProgramFiles\Java\jdk1.6.0_10 CLASSPATH .;%JAVA_HOME%\l ...
- windows内核需要注意的
修改windows内核函数 先屏蔽KdPrint 测试. Hook函数一律使用全局变量 妹的..KiTrap0E 修改.触发了已经断点.但是硬件断点Hook函数里只要使用KdPrint 就蓝屏
- MySQL中的SQL语言
从功能上划分,SQL 语言可以分为DDL,DML和DCL三大类.1. DDL(Data Definition Language)数据定义语言,用于定义和管理 SQL 数据库中的所有对象的语言 :CRE ...
- java jdbc sqlhelper
package com.shop.util; import java.sql.*; //SqlHelper类 //定义了数据库连接函数,关闭查询结果集,关闭Statement对象,关闭数据库连接 // ...
- C语言中float如何存储?
float 内存如何存储的 类型 存储位数 总位数 偏移值 (offset) 数符(S) 阶码(E) 尾数(M) 短实数(float) 1 8 23 32 127 长实数(double) 1 11 5 ...