【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编程基础教程6--shell函数
6.shell函数 6.1.定义函数 简介: shell允许将一组命令集或语句形成一个可用块,这些块成为shell函数 定义函数的格式 ...
- Juery Ajax语法
$.ajax({ url: "/ForgetCard/ForgetLogin",//方法路径URL data: { strUser: $("#textUser" ...
- revert merge会出现的问题
比如当我们git revert的时候, git revert Git会抱怨: is a merge but no -m option was given 这是因为你revert的那个commit是一个 ...
- TortoiseSVN常用批处理命令 分类: C# 2014-08-09 11:31 648人阅读 评论(1) 收藏
TortoiseSVN作为源代码管理软件,估计用过的都会说好,在Windows下,配合批处理命令,往往可以事半功倍,整理了下常用的批处理命令: (将下面的内容修改后,保存为*.bat文件执行即可) : ...
- Linux發送郵件
1.直接使用shell當編輯器 [root@phburdb1 mail]# mail -s "Hello World" juncai.chen@innolux.comHello j ...
- RTP RTCP在音视频传输与同步方面的使用
转自:http://blog.csdn.net/kof98765/article/details/17733701 1 音视频实时传输 1.1 Jrtplib库介绍 本系统采用开源库Jrtplib进行 ...
- javascript中时间的手动创建date的方式
new Date("month dd,yyyy hh:mm:ss"); new Date("month dd,yyyy"); new Date(yyyy,mth ...
- 智能车学习(十二)——智能车原理
一.直立行走任务分解 1.任务分解 (1) 控制车模平衡:通过控制两个电机正反向运动保持车模直立平衡状态 (2) 控制车模速度:通过调节车模的倾角来实现车模速度控制,实际上最后还是演变成通过控制电机的 ...
- nginx、php-fpm、mysql用户权限解析
nginx本身不能处理PHP,它只是个web服务器.当接收到客户端请求后,如果是php请求,则转发给php解释器处理,并把结果返回给客户端.如果是静态页面的话,nginx自身处理,然后把结果返回给客户 ...
- JavaScript设计模式——状态模式
状态和行为: 所谓对象的状态,通常指的就是对象实例的属性的值:而行为指的就是对象的功能,再具体点说,行为大多可以对应到方法上. 状态模式的功能就是分离状态的行为,通过维护状态的变化,来调用不同状态对应 ...