Ikki's Story IV - Panda's Trick (poj 3207 2-SAT)
| 
 Language: 
Default 
Ikki's Story IV - Panda's Trick 
 Description liympanda, one of Ikki’s friend, likes playing games with Ikki. Today after minesweeping with Ikki and winning so many times, he is tired of such easy games and wants to play another game with Ikki. liympanda has a magic circle and he puts it on a plane, there are n points on its boundary in circular border: 0, 1, 2, …, n − 1. Evil panda claims that he is connecting m pairs of points. To connect two points, liympanda either places Despaired at the minesweeping game just played, Ikki is totally at a loss, so he decides to write a program to help him. Input The input contains exactly one test case. In the test case there will be a line consisting of of two integers: n and m (n ≤ 1,000, m ≤ 500). The following m lines each contain two integers ai and bi, which denote Output Output a line, either “ Sample Input 4 2 Sample Output panda is telling the truth... Source 
POJ Monthly--2007.03.04, Ikki 
 | 
题意:有n个点在一个圆上。标号0~n-1。有m条线段告诉两个端点的标号。每条线段能够在画在圆内也能够画在圆外。问这m条线段是否能不向交。
思路:2-SAT模板题,把每条线段当做节点。每条线有两种状态(圆内和圆外。两者仅仅能取其一),建图后求强连通,看 i 和 i‘ 是否在同一个连通分量,若在则无解,否则有解。
參考:由对称性解2-SAT问题 还有 kuangbin神牛的总结点击打开链接
代码:
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define pi acos(-1.0)
#define eps 1e-6
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define DBG pf("Hi\n")
typedef long long ll;
using namespace std; #define INF 0x3f3f3f3f
#define mod 1000000009
const int maxn = 1005;
const int MAXN = 2005;
const int MAXM = 200010;
const int N = 1005; struct Edge
{
int to,next;
}edge[MAXM]; int head[MAXN],tot; void init()
{
tot=0;
memset(head,-1,sizeof(head));
} void addedge(int u,int v)
{
edge[tot].to=v;
edge[tot].next=head[u];
head[u]=tot++;
} int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,scc,top;
bool Instack[MAXN]; void Tarjan(int u)
{
int v;
Low[u]=DFN[u]=++Index;
Stack[top++]=u;
Instack[u]=true;
for (int i=head[u];~i;i=edge[i].next)
{
v=edge[i].to;
if (!DFN[v])
{
Tarjan(v);
if (Low[u]>Low[v])
Low[u]=Low[v];
}
else if (Instack[v]&&Low[u]>DFN[v])
Low[u]=DFN[v];
}
if (Low[u]==DFN[u])
{
++scc;
do{
v=Stack[--top];
Instack[v]=false;
Belong[v]=scc;
}while (v!=u);
}
return ;
} bool solvable(int n)
{
memset(DFN,0,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
Index=scc=top=0;
for (int i=0;i<n;i+=2)
if (!DFN[i])
Tarjan(i);
for (int i=0;i<n;i+=2)
{
if (Belong[i]==Belong[i^1])
return false;
}
return true;
} struct Line
{
int s,t;
}line[MAXN]; int n,m; int main()
{
#ifndef ONLINE_JUDGE
freopen("C:/Users/lyf/Desktop/IN.txt","r",stdin);
#endif
int i,j;
scanf("%d%d",&n,&m);
init();
for (i=0;i<m;i++)
{
scanf("%d%d",&line[i].s,&line[i].t);
if (line[i].s>line[i].t) swap(line[i].s,line[i].t);
}
for (i=0;i<m;i++)
{
for (j=i+1;j<m;j++)
{
if (line[i].s<line[j].s&&line[i].t>line[j].s&&line[i].t<line[j].t||line[j].s<line[i].s&&line[j].t>line[i].s&&line[j].t<line[i].t)
{
addedge(2*i,2*j+1);
addedge(2*j+1,2*i);
addedge(2*j,2*i+1);
addedge(2*i+1,2*j);
}
}
}
if (solvable(m*2))
printf("panda is telling the truth...\n");
else
printf("the evil panda is lying again\n");
return 0;
}
Ikki's Story IV - Panda's Trick (poj 3207 2-SAT)的更多相关文章
- [2-SAT] poj 3207 Ikki's Story IV - Panda's Trick
		
题目链接: id=3207">http://poj.org/problem? id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1 ...
 - POJ 3207 Ikki's Story IV - Panda's Trick(2-sat)
		
POJ 3207 Ikki's Story IV - Panda's Trick id=3207" target="_blank" style=""& ...
 - POJ 3207 Ikki's Story IV - Panda's Trick (2-SAT)
		
职务地址:id=3207">POJ 3207 找好矛盾关系.矛盾关系是(2,5)和(3,6)这两个仅仅能一个在外边,一个在里边.利用这个矛盾关系来建图. 能够用在外边和里边来当1和0, ...
 - Ikki's Story IV - Panda's Trick POJ - 3207(水2 - sat 在圈内 还是 在圈外)
		
题意: 就是一个圈上有n个点,给出m对个点,这m对个点,每一对都有一条边,合理安排这些边在圈内或圈外,能否不相交 解析: 我手残 我手残 我手残 写一下情况 只能是一个在圈外 一个在圈内 即一个1一个 ...
 - POJ 3207 Ikki's Story IV - Panda's Trick
		
Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 7296 ...
 - poj 3207 Ikki's Story IV - Panda's Trick (2-SAT)
		
http://poj.org/problem?id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 13 ...
 - POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题)
		
POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题) Description liympanda, one of Ikki's friend, likes ...
 - 【POJ3207】Ikki's Story IV - Panda's Trick
		
POJ 3207 Ikki's Story IV - Panda's Trick liympanda, one of Ikki's friend, likes playing games with I ...
 - POJ  3207  Ikki's Story IV - Panda's Trick (2-sat)
		
Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 6691 ...
 
随机推荐
- Python-约瑟夫环
			
n个人(以编号0,1,2,3...n-1分别表示)围坐在一张圆桌周围.从编号为0的人开始报数1,数到m的那个人出列: 他的下一个人又从1开始报数,数到m的那个人又出列:依此规律重复下去,直到圆桌周围的 ...
 - Android自动化测试Uiautomator--UiCollection接口简介
			
这个对象可以理解为一个对象的集合,因为UiSelector描述后得到的有可能是多个满足条件的控件集合,因此可以用来生成UiCollection,继承自UiObject. 用于枚举一个容器的用户界面(U ...
 - MySQL MGR集群搭建
			
本文来自网易云社区,转载务必请注明出处. 本文将从零开始搭建一个MySQL Group Replication集群,包含3个节点.简单介绍如何查询MGR集群状态信息.并介绍如何进行MGR节点上下线操作 ...
 - Python内置函数6
			
Python内置函数6 1.license() 输出当前python 的license信息 A. HISTORY OF THE SOFTWARE ========================== ...
 - 多线程下,多次操作数据库报错,There is already an open DataReader associated with this Command which must be closed first.
			
原文:https://www.cnblogs.com/sdusrz/p/4433108.html 执行SqlDataReader.Read之后,如果还想用另一个SqlCommand执行Insert或者 ...
 - POJ-2186 Popular Cows,tarjan缩点找出度为0的点。
			
Popular Cows 题意:一只牛崇拜另外一只牛,这种崇拜关系可以传导.A->B,B->C =>A->C.现在给出所有的关系问你有多少牛被其他所有的牛都崇拜. 思路:就是一 ...
 - 北京集训TEST13——PA(Goodness)
			
题目: Description 桌面上放有 n 张卡牌.对于每张卡牌,一面是绿色的,另一面是红色的.卡牌的每一面都标有一个整数.对于卡牌a和卡牌b,卡牌a对卡牌b的好感度为卡牌a绿色面的数与卡牌b红色 ...
 - eclipse导入svn检出的maven项目问题
			
1.修改项目jdk环境和编译环境.消除红叉. 2.windows-preferences-java-installed jres,修改工作空间的jdk,在Default vm arguments栏中添 ...
 - Linux 下运行 C++ 程序出现 “段错误(核心已转储)”
			
Linux下写C++程序出现“段错误(核心已转储)”的问题: 段错误一般就是指访问的内存超出了系统所给这个程序的内存空间,通常这个值是由gdtr来保存的,他是一个48位的寄存器,其中的32位是保存由它 ...
 - hdu3038 How Many Answers Are Wrong
			
TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always wo ...