zoukankan      html  css  js  c++  java
  • POJ

    链接:

    https://vjudge.net/problem/POJ-3207

    题意:

    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.

    思路:

    对于两个相交的坐标,不能同时连里面或外面,所以一个连里面,一个连外面,加入图中,判断一下。

    代码:

    //#include<bits/stdc++.h>
    #include<iostream>
    #include<string>
    #include<cstdio>
    #include<vector>
    #include<string.h>
    #include<cstring>
    #include<set>
    #include<queue>
    #include<algorithm>
    #include<math.h>
    #include<stdio.h>
    #include<map>
    #include<stack>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    const int MOD = 20071027;
    const int MAXN = 1e3+10;
    int Next[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
    
    int n, m;
    vector<int> G[MAXN*2];
    stack<int> St;
    int sccnum[MAXN*2], dfn[MAXN*2], low[MAXN*2];
    int u[MAXN*2], v[MAXN*2];
    int dfn_clock, scc_cnt;
    
    void tarjan(int u)
    {
        dfn[u] = low[u] = ++dfn_clock;
        St.push(u);
        for (int i = 0;i < (int)G[u].size();i++)
        {
            int v = G[u][i];
            if (!dfn[v])
            {
                tarjan(v);
                low[u] = min(low[u], low[v]);
            }
            else if (!sccnum[v])
                low[u] = min(low[u], dfn[v]);
        }
        if (low[u] == dfn[u])
        {
            ++scc_cnt;
            while(true)
            {
                int x = St.top();
                St.pop();
                sccnum[x] = scc_cnt;
                if (x == u)
                    break;
            }
        }
    }
    
    bool solve()
    {
        memset(sccnum, 0, sizeof(sccnum));
        memset(dfn, 0, sizeof(dfn));
        memset(low, 0, sizeof(low));
        dfn_clock = scc_cnt = 0;
        for (int i = 0;i < 2*m;i++)
            if (!dfn[i]) tarjan(i);
        for (int i = 0;i < 2*m;i+=2)
            if (sccnum[i] == sccnum[i^1]) return false;
        return true;
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
        cin >> n >> m;
        for (int i = 0;i < m;i++)
        {
            cin >> u[i] >> v[i];
            if (u[i] > v[i]) swap(u[i], v[i]);
        }
        for (int i = 0;i < 2*m;i++)
            G[i].clear();
        for (int i = 0;i < m;i++)
        {
            for (int j = i+1;j < m;j++)
            {
                int l = i*2, r = j*2;
                if ((u[i] < u[j] && v[i] > u[j] && v[j] > v[i]) || (u[j] < u[i] && u[i] < v[j] && v[j] < v[i]))
                {
                    G[l].push_back(r^1);
                    G[l^1].push_back(r);
                    G[r].push_back(l^1);
                    G[r^1].push_back(l);
                }
            }
        }
        if (solve())
            puts("panda is telling the truth...");
        else
            puts("the evil panda is lying again");
    
        return 0;
    }
    
  • 相关阅读:
    使用transfor让图片旋转
    block与inline,inline和inline-block,块级和行内元素,行内替换和行内非替换元素
    使用classList来实现两个按钮样式的切换
    关于css透明度的问题
    级动(两级联动)思路分享
    js图片预览(一张图片预览)
    js关于密码框强弱度的提示
    javascript对象与实例
    javascript 逻辑运算符
    Raphael画圆弧
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12149909.html
Copyright © 2011-2022 走看看