Ikki's Story IV - Panda's Trick POJ - 3207(水2 - sat 在圈内 还是 在圈外)

题意:

  就是一个圈上有n个点,给出m对个点,这m对个点,每一对都有一条边,合理安排这些边在圈内或圈外,能否不相交

解析:

  我手残 我手残 我手残

写一下情况 只能是一个在圈外 一个在圈内

即一个1一个0

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define pd(a) printf("%d\n", a);
#define plld(a) printf("%lld\n", a);
#define pc(a) printf("%c\n", a);
#define ps(a) printf("%s\n", a);
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 1e5 + 10, INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
int n, m;
int sccno[maxn], vis[maxn], low[maxn], scc_cnt, scc_clock;
stack<int> S;
vector<int> G[maxn];
struct node
{
    int x, y;
}Node[maxn];

void init()
{
    mem(sccno, 0);
    mem(vis, 0);
    mem(low, 0);
    for(int i = 0; i < maxn; i++) G[i].clear();
    scc_cnt = scc_clock = 0;
}

void dfs(int u)
{
    low[u] = vis[u] = ++scc_clock;
    S.push(u);
    for(int i = 0; i < G[u].size(); i++)
    {
        int v = G[u][i];
        if(!vis[v])
        {
            dfs(v);
            low[u] = min(low[u], low[v]);
        }
        else if(!sccno[v])
            low[u] = min(low[u], vis[v]);
    }
    if(vis[u] == low[u])
    {
        scc_cnt++;
        for(;;)
        {
            int x = S.top(); S.pop();
            sccno[x] = scc_cnt;
            if(x == u) break;
        }
    }
}

bool check()
{
    for(int i = 0; i < n * 2; i += 2)
        if(sccno[i] == sccno[i^1])
            return false;
    return true;
}

int main()
{
    init();
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        cin >> Node[i].x >> Node[i].y;
    }
    for(int i = 0; i < m; i++)
    {
        for(int j = i + 1; j < m; j++)
        {
            int x1 = Node[i].x, y1 = Node[i].y, x2 = Node[j].x, y2 = Node[j].y;
            if(x1 > y1) swap(x1, y1);
            if(x2 > y2) swap(x2, y2);
            if(x2 > x1 && x2 < y1 && y2 > y1 || x2 < x1 && y2 > x1 && y2 < y1 || x1 > x2 && x1 < y2 && y1 > y2 || x1 < x2 && y1 > x2 && y1 < y2)
            {
                G[i << 1 | 1].push_back(j << 1);
                G[j << 1].push_back(i << 1 | 1);
                G[j << 1 | 1].push_back(i << 1);
                G[i << 1].push_back(j << 1 | 1);
            }
        }
    }
    for(int i = 0; i < n * 2; i++)
        if(!vis[i]) dfs(i);
    if(check()) cout << "panda is telling the truth..." << endl;
    else cout << "the evil panda is lying again" << endl;

    return 0;
}

 

posted @ 2018-10-18 19:37  WTSRUVF  阅读(136)  评论(0编辑  收藏  举报