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 ...
随机推荐
- 数据结构( Pyhon 语言描述 ) — — 第6章:继承和抽象类
继承 新的类通过继承可以获得已有类的所有特性和行为 继承允许两个类(子类和超类)之间共享数据和方法 可以复用已有的代码,从而消除冗余性 使得软件系统的维护和验证变得简单 子类通过修改自己的方法或者添加 ...
- 爬虫练习四:爬取b站番剧字幕
由于个人经常在空闲时间在b站看些小视频欢乐一下,这次就想到了爬取b站视频的弹幕. 这里就以番剧<我的妹妹不可能那么可爱>第一季为例,抓取这一番剧每一话对应的弹幕. 1. 分析页面 这部番剧 ...
- 【HIHOCODER 1067】最近公共祖先·二(LCA)
描述 上上回说到,小Hi和小Ho用非常拙劣--或者说粗糙的手段山寨出了一个神奇的网站,这个网站可以计算出某两个人的所有共同祖先中辈分最低的一个是谁.远在美国的他们利用了一些奇妙的技术获得了国内许多人的 ...
- 20130829ios cocos2d下拉列表的向上弹出实现(ios开发遇到的frame的问题)
前几天仔细区分了ios中frame,bounds,center之间的关系. Frame:边框矩形,是视图相对于其父坐标的位置和大小 Bounds:边界矩形,是本地坐标系统(一般较少使用) Center ...
- 安卓启动图去除顶部title和状态栏
1.在启动页的xml配置中,设置layout的id, <?xml version="1.0" encoding="utf-8"?> <Line ...
- node.js中的http.request方法使用说明
http.get(options, callback) 由于该方法属于http模块,使用前需要引入http模块(var http= require(“http”) ) 接收参数: option 数 ...
- selenium 切换窗口的几种方法
第一种方法: 使用场景: 打开多个窗口,需要定位到新打开的窗口 使用方法: # 获取打开的多个窗口句柄 windows = driver.window_handles # 切换到当前最新打开的窗口 d ...
- hlgoj1881
#include <stdio.h> +]; int main(){ int l,m; int i,j; int sign; num[]=; num[]=; while(~scanf(&q ...
- poj2431 Expedition优先队列
Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Bein ...
- WebLoad XML-parser methods
WebLOAD provides an embedded, third-party XML parser object to improve the multi-platform support fo ...