Ikki ' s story Iv-panda's Trick
Time Limit: 1000MS |
|
Memory Limit: 131072K |
Total Submissions: 8175 |
|
Accepted: 3011 |
Description
Liympanda, one of Ikki ' s friend, likes playing games with Ikki. Today after minesweeping with Ikki and winning so many times, he's tired of such easy games and wants to play another GAM E with Ikki.
Liympanda have a magic circle and he puts it on a plane, there is 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 points, Liympanda either places the link entirely inside the circle or entirely outside the circle. Now Liympanda tells Ikki no-links Touch inside/outside the circle, except on the boundary. He wants Ikki to figure out whether the is possible ...
Despaired at the minesweeping game just played, Ikki are 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 would be a line consisting of of of of the integers: n and m (n ≤1,000, m< /c3>≤500). The following m lines each contain integers ai and bi, which denote the endpoints of the ith wire. Every point would have the most one link.
Output
Output a line, either " panda is telling the truth...
" or " the evil panda is lying again
.
Sample Input
4 20 13 2
Sample Output
Panda is telling the truth ...
Source
POJ monthly--2007.03.04, Ikki
2-sat judge the feasibility template problem.
Test instructions is:
Give a circle, give m points, points and points have a connection between the line can be in the circle or outside the circle, can be straight and curved. Ask if these line segments do not want to be handed.
Wired in the circle or outside the circle, for two options, consider 2-sat.
cannot be in a circle or outside the circle at the same time:
The connection between two points and the other two points crosses in the circle or outside the circle.
#include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include < cmath> #include <stack> #include <cstring>using namespace Std;int tot=0,n,m,a[5000],b[5000],h[5000], pre[5000],lowlink[5000],dfs_clock=0,scc_cnt=0,sccno[5000];stack<int> s;struct edge{int Y,ne;} E[1000000];void Add (int x,int y) {tot++;e[tot].ne=h[x];e[tot].y=y;h[x]=tot;} void Dfs (int u) {pre[u]=lowlink[u]=++dfs_clock;s.push (U); for (int i=h[u];i;i=e[i].ne) {int v=e[i].y;if (!pre[v]) {DFS (v ); Lowlink[u]=min (Lowlink[v],lowlink[u]);} else if (!sccno[v]) lowlink[u]=min (Lowlink[u],pre[v]);} if (Lowlink[u]==pre[u]) {scc_cnt++;for (;;) {int x=s.top (); S.pop (); sccno[x]=scc_cnt;if (x==u) Break;}}} void Findscc () {Dfs_clock=scc_cnt=0;memset (pre,0,sizeof (pre)); Memset (Sccno,0,sizeof (SCCNO)); for (int i=1;i<=2*m ; i++) if (!pre[i]) DFS (i);} int main () {scanf ("%d%d", &n,&m), for (int i=1;i<=m;i++) {scanf ("%d%d", &a[i],&b[i]); if (a[i]>b[i ]) Swap (a[i],b[i]);} for (int i=1;i<=m;i++) for (int j=i+1;j<=m;j++) if ((A[i]<a[j]&&b[i]<b[j]&&b[i]>a[j]) | | (A[i]>a[j]&&b[i]>b[j]&&a[i]<b[j])) cannot be in a circle or outside {Add (i,j+m) at the same time; ADD (I+M,J); ADD (J,I+M); ADD (j+m,i);} FINDSCC (); for (int. i=1;i<=m;i++) if (Sccno[i]==sccno[i+m]) {printf ("The Evil Panda is lying again\n"); return 0;} printf ("Panda is telling the truth...\n"); return 0;}
Sentiment:
1.CE is the header file forgot to hit <cstring>
Re is the storage edge of the array open too small!!
The key to 2.2-sat's problem is to find out which of the two is, and what to choose between.
"POJ 3207" Ikki's story Iv-panda ' s Trick