"The main effect of the topic"
There are n numbers on a circle: 0,1,2 ... N-1. Then there is the M line 22 connecting these dots, which can be inside the circle or outside the circle. Ask if there is a way to make these lines do not intersect.
Ideas
In lines, each line is either inside the circle or outside the circle, a typical 2-sat model.
Code
#include <iostream> #include <cstdio> #include <cstring> using namespace std;
typedef long long Int64;
const int MAXN = 1010;
const int VN = MAXN*2;
const int EN = VN*VN/2;
int n, m;
int arr[vn][2];
struct graph{int size;
int HEAD[VN];
struct{int V, next;
}e[en];
void init () {size = 0;
Memset (Head,-1, sizeof (head));
} void Addedge (int u, int v) {e[size].v = v;
E[size].next = Head[u];
Head[u] = size++;
}}g;
Class two_sat{Public:bool Check (const graph& g, const int n) {SCC (g, N);
for (int i=0; i<n; ++i) if (belong[i] = = Belong[i+n]) return false;
return true;
} private:void Tarjan (const graph& g, const int u) {int V;
Dfn[u] = low[u] = ++idx;
sta[top++] = u; Instack[u] = True;
for (int e=g.head[u]; E!=-1 e=g.e[e].next) {v = g.e[e].v;
if (dfn[v] = =-1) {Tarjan (g, v);
Low[u] = min (Low[u], low[v]);
}else if (Instack[v]) {Low[u] = min (Low[u], dfn[v]);
} if (dfn[u] = = Low[u]) {++bcnt;
do{v = sta[--top];
INSTACK[V] = false;
BELONG[V] = bcnt;
}while (U!= v);
} void SCC (const graph& g, const int n) {idx = top = bcnt = 0;
memset (DFN,-1, sizeof (DFN));
memset (instack, 0, sizeof (instack));
for (int i=0; i<2*n; ++i) if (dfn[i] = = 1) Tarjan (g, I);
} private:int idx, top, bcnt;
int DFN[VN];
int LOW[VN];
int STA[VN];
int BELONG[VN];
BOOL INSTACK[VN];
}sat; boolIscross (int* A, int *b) {return a[0]>b[0]&&a[0]<b[1] && (a[1]<b[0) | | A[1]>B[1]) | | A[1]>b[0]&&a[1]<b[1] && (a[0]<b[0) | |
A[0]>B[1]);
int main () {while (~scanf ("%d%d", &n, &m)) {g.init ();
for (int i=0; i<n; ++i) {scanf ("%d%d", &arr[i][0], &arr[i][1]);
if (Arr[i][0] > Arr[i][1]) swap (arr[i][0], arr[i][1]); for (int i=0; i<n; ++i) {for (int j=i+1; j<n; ++j) {if (Iscross (arr[i)
, Arr[j]) {G.addedge (I, j+n);
G.addedge (I+n, J);
G.addedge (J, I+n);
G.addedge (J+n, i);
}} if (Sat.check (g, N)) puts ("Panda is telling the truth ...");
Else puts ("The evil Panda is lying again");
return 0; }
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/