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模板题的更多相关文章

  1. [AHOI 2009] 维护序列(线段树模板题)

    1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec  Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...

  2. HDU 2222 AC自动机模板题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...

  3. POJ2774 & 后缀数组模板题

    题意: 求两个字符串的LCP SOL: 模板题.连一起搞一搞就好了...主要是记录一下做(sha)题(bi)过程心(cao)得(dan)体(xin)会(qing) 后缀数组概念...还算是简单的,过程 ...

  4. HDU 1251 Trie树模板题

    1.HDU 1251 统计难题  Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...

  5. HDU-3549 最大流模板题

    1.HDU-3549   Flow Problem 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 3.总结:模板题,参考了 http://ww ...

  6. HDU 4280:Island Transport(ISAP模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...

  7. HDU-2222 Keywords Search(AC自动机--模板题)

    题目大意:统计一共出现了多少次模板串. 题目分析:AC自动机的模板题.不过这题有坑,相同的模板串不能只算一次. 代码如下: # include<iostream> # include< ...

  8. Dancing Link --- 模板题 HUST 1017 - Exact cover

    1017 - Exact cover Problem's Link:   http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...

  9. AC自动机 - 多模式串匹配问题的基本运用 + 模板题 --- HDU 2222

    Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  10. POJ 2387 Til the Cows Come Home --最短路模板题

    Dijkstra模板题,也可以用Floyd算法. 关于Dijkstra算法有两种写法,只有一点细节不同,思想是一样的. 写法1: #include <iostream> #include ...

随机推荐

  1. node.js---sails项目开发(2)

    1.安装mongoDB,这里用brew安装 brew install mongodb 2. 启动数据库 mongod 3.再打开一个终端,连接数据库 mongo 4.启动成功后,接下来就是新建一个数据 ...

  2. golang SQLite3性能测试

    SQLite是个小型的数据库,很简洁,即支持文件也支持内存,比较适合小型的独立项目,在没有网络的时候做一些复杂的关系数据存储和运算. 为了考察性能做10M(1000万)条记录的测试,测试机4CPU.8 ...

  3. php foreach函数的用法

    php foreach函数用法举例.  Foreach 函数(PHP4/PHP5) foreach 语法结构提供了遍历数组的简单方式. foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类 ...

  4. STL 中的链表排序

    一直以来学习排序算法, 都没有在链表排序上下太多功夫,因为用得不多.最近看STL源码,才发现,原来即使是链表,也能有时间复杂度为O(nlogn)的算法, 大大出乎我的意料之外,一般就能想到个插入排序. ...

  5. sqlserver建立相同的表结构

    select * into purpose from source 来自为知笔记(Wiz)

  6. 微信小程序组件checkbox

    表单组件checkbox:官方文档 Demo Code: JS Page({ data:{ items:[ {name: 'USA', value: '美国'}, {name: 'CHN', valu ...

  7. HBase在数据统计应用中的使用心得

    转载自:http://www.cnblogs.com/panfeng412/archive/2011/11/19/2254921.html 1. 数据统计的需求 互联网上对于数据的统计,一个重要的应用 ...

  8. 【Flask】WTForms文件上传下载

    # 文件上传笔记:1. 在模版中,form表单中,需要指定`encotype='multipart/form-data'`才能上传文件.2. 在后台如果想要获取上传的文件,那么应该使用`request ...

  9. zabbix监控nginx的性能

    1.nginx配置 需要使用zabbix监控nginx,首先nginx需要配置ngx_status,在nginx的配置文件中加入红框中的配置,然后重启nginx如下图所示: location /ngx ...

  10. Oracle数据库使用总结

    --1.使用月份作为条件筛选(to_char函数与extract函数使用) select * from test_date where to_char(dqsj,'mm') like '%07%'; ...