zoukankan      html  css  js  c++  java
  • ural Episode Nth: The Jedi Tournament(缩点+建树)

    题意:有N个武士,衡量每个武士的综合实力由三个因素:length of the lightsaber, Force, Light side in this order,如果一个武士的其中任意两项大于另一个武士,那么他会获得胜利,题目要求可能获得最后胜利的那个人。获得最后胜利就是打败所有的人。

    思路:如果A可以打败B,B可以打败C,C又可以打败A的话,那么总是存在一种方案可以使这其中的任何一人获得最后的胜利,所以先进行缩点,然后建树,此时树的根节点里的所有人都有可能获得最后的胜利。

    代码:

    View Code
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <math.h>
    #include <map>
    #include <stack>
    #include <vector>
    #define  N 204
    #define  INF 1000000000
    using namespace std ;
    
    struct node
    {
        char name[34] ;
        int a , b , c ;
    }p[N] ;
    
    int mp[N][N] , dfn[N] , low[N] ;
    bool used[N] , vist[N] ;
    int belong[N] ;
    int cnt , id , n ;
    stack<int>q ;
    
    void init()
    {
        int i , j ;
    
        for ( i = 1 ; i <= n ; i++ )
        {
            dfn[i] = low[i] = 0 ;
            used[i] = vist[i] = false ;
            for ( j = 1 ; j <= n ; j++ )
            mp[i][j] = 0 ;
        }
        cnt = id = 0 ;
        while( !q.empty()) q.pop();
    }
    
    void Tarjan( int x )
    {
        dfn[x] = low[x] = ++id ;
        used[x] = vist[x] = true ;
        q.push( x ) ;
    
        for( int i = 1 ; i <= n ; i++ )
        {
            if ( mp[x][i] )
            {
                if( !used[i] )
                {
                    Tarjan( i ) ;
                    low[x] = min( low[x] , low[i] ) ;
                }
                else if ( vist[i] )
                {
                    low[x] = min( low[x] , dfn[i] ) ;
                }
            }
        }
        if ( dfn[x] == low[x] )
        {
            cnt++ ;
            int u ;
            do
            {
                u = q.top() ;
                q.pop();
                vist[u] = false ;
                belong[u] = cnt ;
            }while( u != x ) ;
        }
    }
    
    int jud( node x , node y )
    {
        if (( x.a > y.a && x.b > y.b ) || ( x.a > y.a && x.c > y.c ) || ( x.b>y.b&&x.c>y.c))
        {
            return 1 ;
        }
        else
        {
            return -1 ;
        }
    }
    
    int main()
    {
        int i , j , k ;
        bool num[N] ;
    
        while( cin>>n )
        {
            for ( i = 1 ; i <= n ; i++ )
            {
                cin>>p[i].name>>p[i].a>>p[i].b>>p[i].c ;
            }
            init() ;
            for ( i = 1 ; i <= n ; i++ )
            {
                for ( j = 1 ; j <= n ; j++ )
                {
                    k = jud( p[i] , p[j] ) ;
                    if ( k > 0 )
                    mp[i][j] = true ;
                }
            }
    
            for ( i = 1 ; i <= n ; i++ )
            {
                if ( !dfn[i] )
                Tarjan( i ) ;
            }
    
            memset( num , true , sizeof ( num )) ;
            for ( i = 1 ; i <= n ; i++ )
            {
                for ( j = 1 ; j <= n ; j++ )
                if ( mp[i][j] && belong[i] != belong[j] )
                num[belong[j]] = false ;
            }
    
            for( i = 1 ; i <= n ; i++ )
            if ( num[belong[i]] )
            printf ( "%s\n" , p[i].name ) ;
        }
        return 0 ;
    }
  • 相关阅读:
    标准库中的生成器函数
    Python 数据分析5
    Chrome 开发者工具(三)------ Sources
    Chrome 开发者工具(二)------ Console
    Chrome 开发者工具 F12(一)
    jquery 获取自定义属性的值 data-*
    PHP 常用函数备忘
    Winsows 服务器,PHP 开发环境搭建
    FuelPHP 查看 Query SQL
    Laravel —— could not find driver
  • 原文地址:https://www.cnblogs.com/misty1/p/2877511.html
Copyright © 2011-2022 走看看