poj32072-sat模板题
tarjan扫一遍后直接判断
最关键的地方就是建边(x[i] <= x[j] && y[i] >= x[j] && y[i] <= y[j]) || (x[i] >= x[j] && x[i] <= y[j] && y[i] >= y[j])
建边条件:x[ i ] < = x [ j ] < = y [ i ] < =y [ j ]或者 x [ j ] < = x [ i ] < = y [ j ] < = y [ i ]
这样的话 i 和 j 肯定是相交的,那么连边 ~i ,j 和 i,~j 这样保证了 i 和 j 是不相交的
如果同一个点的拆分在同一个强连通分量里面,那么就无法实现(因为这样i在同一个环中了)
注意 i 和 i + 1是同一个点拆分得到的
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; stack<int>s;
int dfn[N],low[N];
int inans[N],ins[N];
int num,index;
int n,m;
int x[N],y[N];
vector<int>v[N];
void tarjan(int u)
{
ins[u]=;
dfn[u]=low[u]=++index;
s.push(u);
for(int i=;i<v[u].size();i++)
{
int x=v[u][i];
if(dfn[x]==)
{
tarjan(x);
low[u]=min(low[u],low[x]);
}
else if(ins[x]==)low[u]=min(low[u],dfn[x]);
}
if(dfn[u]==low[u])
{
++num;
while(!s.empty()){
int k=s.top();
s.pop();
ins[k]=;
inans[k]=num;
if(k==u)break;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
memset(inans,,sizeof inans);
memset(ins,,sizeof ins);
memset(dfn,,sizeof dfn);
memset(low,,sizeof low);
for(int i=;i<=*m;i++)v[i].clear();
while(!s.empty())s.pop();
index=num=;
cin>>n>>m;
for(int i=;i<=m;i++)
{
cin>>x[i]>>y[i];
if(x[i]>y[i])swap(x[i],y[i]);
}
for(int i=;i<=m;i++)
for(int j=i+;j<=m;j++)
if((x[i] <= x[j] && y[i] >= x[j] && y[i] <= y[j]) || (x[i] >= x[j] && x[i] <= y[j] && y[i] >= y[j]))
{
v[*i-].push_back(*j);
v[*j].push_back(*i-);
v[*j-].push_back(*i);
v[*i].push_back(*j-);
}
for(int i=;i<=*m;i++)
if(!dfn[i])
tarjan(i);
bool f=;
for(int i=;i<*m;i+=)
if(inans[i]==inans[i+])
{
f=;
break;
}
if(f)cout<<"the evil panda is lying again"<<endl;
else cout<<"panda is telling the truth..."<<endl;
return ;
}
/******************** ********************/
poj32072-sat模板题的更多相关文章
- [AHOI 2009] 维护序列(线段树模板题)
1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...
- HDU 2222 AC自动机模板题
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...
- POJ2774 & 后缀数组模板题
题意: 求两个字符串的LCP SOL: 模板题.连一起搞一搞就好了...主要是记录一下做(sha)题(bi)过程心(cao)得(dan)体(xin)会(qing) 后缀数组概念...还算是简单的,过程 ...
- HDU 1251 Trie树模板题
1.HDU 1251 统计难题 Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...
- HDU-3549 最大流模板题
1.HDU-3549 Flow Problem 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 3.总结:模板题,参考了 http://ww ...
- HDU 4280:Island Transport(ISAP模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...
- HDU-2222 Keywords Search(AC自动机--模板题)
题目大意:统计一共出现了多少次模板串. 题目分析:AC自动机的模板题.不过这题有坑,相同的模板串不能只算一次. 代码如下: # include<iostream> # include< ...
- Dancing Link --- 模板题 HUST 1017 - Exact cover
1017 - Exact cover Problem's Link: http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...
- AC自动机 - 多模式串匹配问题的基本运用 + 模板题 --- HDU 2222
Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- POJ 2387 Til the Cows Come Home --最短路模板题
Dijkstra模板题,也可以用Floyd算法. 关于Dijkstra算法有两种写法,只有一点细节不同,思想是一样的. 写法1: #include <iostream> #include ...
随机推荐
- numpy.random.random & numpy.ndarray.astype & numpy.arange
今天看到这样一句代码: xb = np.random.random((nb, d)).astype('float32') #创建一个二维随机数矩阵(nb行d列) xb[:, 0] += np.aran ...
- pandas 报错:【sys:1: DtypeWarning: Columns (15) have mixed types. Specify dtype option on import or set low_memory=False.】
错误原因 报错提示:“sys:1: DtypeWarning: Columns (15) have mixed types. Specify dtype option on import or set ...
- django中的setting全局变量的导入
需求:在py文件中导入settings.py中的变量BASE_DIR settings.py文件 import os # Build paths inside the project like thi ...
- Java集合类学习记录
被标记为transient的属性在对象被序列化的时候不会被保存int[] arr1 = {1, 2, 3, 4, 5}; int[] arr2 = Arrays.copyOf(arr1, new_le ...
- python-绘图matplotlib
<Python编程:从入门到实践>读书笔记 1.使用plot()绘制简单的折线图 import matplotlib.pyplot as plt va=[1,2,3,4,5] sq=[1, ...
- python提示AttributeError: 'NoneType' object has no attribute 'append'
在写python脚本时遇到AttributeError: 'NoneType' object has no attribute 'append' a=[] b=[1,2,3,4] a = a.appe ...
- django联合查询
假设A表的主键aid作为B表的外键,A表有属性name,那么想查询B表中name为abc的元素就可以这样写: B.objects.all().filter(aid__name = 'abc') __真 ...
- linux 基础知识总结
1. 查看目录文件命令: 查看以f开头的文件:ll f* 查看/usr/local目录下的文件:ll /usr/local 按最后的修改的时间顺序,列出:ll -t */f* ...
- 针对Oracle表 列字段的增加、删除、修改以及重命名操作sql
增加字段语法:alter table tablename add (column datatype [default value][null/not null],….); 说明:alter table ...
- Javascript中call()和apply()的用法 ----1
1.方法定义 call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call ...