POJ 3207 Ikki's Story IV - Panda&…
2018-06-17 21:09:09来源:未知 阅读 ()
Time Limit: 1000MS | Memory Limit: 131072K | |
Total Submissions: 10870 | Accepted: 3988 |
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 the link entirely inside the circle or entirely outside the circle. Now liympanda tells Ikki no two links touch inside/outside the circle, except on the boundary. He wants Ikki to figure out whether this is possible…
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 the endpoints of the ith wire. Every point will have at most one link.
Output
Output a line, either “panda is telling the truth...
” or “the evil panda is lying again
”.
Sample Input
4 2 0 1 3 2
Sample Output
panda is telling the truth...
题意:有一个圆,给出一些边连接着两个点,边可以从圆里连,也可以从圆外连,问是否可以不相交
对于边$i,j$限制条件为不相交,即不在同一个集合中
因此我们将这个问题转化为了2-SAT问题
设$i$表示边$i$在圆内,$i'$表示$i$在圆外
若$(i,j)$在圆内相交,那么它们在圆外也一定相交
如果边$i,j$在圆内相交
那么就从$i$连向$j'$(i内j外),从$j'$连向$i$(i内j外),从$j$连向$i'$(j内i外),从$i'$连向$j$(j内i外)
然后来一遍tarjan就好了
#include<cstdio> #include<cstring> #include<algorithm> #include<stack> #define Pair pair<int,int> #define F first #define S second using namespace std; const int MAXN=1e6+10; #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++) char buf[1<<20],*p1=buf,*p2=buf; inline int read() { char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } Pair p[MAXN]; struct node { int u,v,nxt; }edge[MAXN]; int head[MAXN],num=1; inline void AddEdge(int x,int y) { edge[num].u=x; edge[num].v=y; edge[num].nxt=head[x]; head[x]=num++; } int dfn[MAXN],low[MAXN],vis[MAXN],color[MAXN],colornum=0,tot=0; stack<int>s; void tarjan(int now) { dfn[now]=low[now]=++tot; s.push(now); vis[now]=1; for(int i=head[now];i!=-1;i=edge[i].nxt) { if(!dfn[edge[i].v]) tarjan(edge[i].v),low[now]=min(low[now],low[edge[i].v]); if(vis[edge[i].v]) low[now]=min(low[now],dfn[edge[i].v]); } if(dfn[now]==low[now]) { colornum++; int h=0; do { h=s.top();s.pop(); vis[h]=0; color[h]=colornum; }while(h!=now); } } int main() { #ifdef WIN32 freopen("a.in","r",stdin); #else #endif memset(head,-1,sizeof(head)); int N=read(),M=read(); for(int i=1;i<=M;i++) { p[i].F=read(),p[i].S=read(); if(p[i].F>p[i].S) swap(p[i].F,p[i].S); } for(int i=1;i<=M;i++) { for(int j=i+1;j<=M;j++) { if((p[j].F>=p[i].F&&p[j].F<=p[i].S&&p[j].S>=p[i].S)|| (p[j].F<=p[i].F&&p[j].S>=p[i].F&&p[j].S<=p[i].S)) AddEdge(i,j+M), AddEdge(j,i+M), AddEdge(j+M,i), AddEdge(i+M,j); } } for(int i=1;i<=M;i++) if(!dfn[i]) tarjan(i); bool flag=1; for(int i=1;i<=M;i++) if(color[i]==color[i+M]) {printf("the evil panda is lying again\n");flag=0;break;} if(flag==1) printf("panda is telling the truth...\n"); return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- POJ-3278 2020-04-01
- Asteroids!_poj2225 2020-02-09
- poj-1753题题解思路 2020-01-26
- POJ1852 2019-11-11
- POJ2431 优先队列+贪心 - biaobiao88 2019-11-03
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash