• hihoCoder #1870 : Jin Yong’s Wukong Ranking List-闭包传递(递归) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction A) 2018 ICPC 北京区域赛现场赛A


    P1 : Jin Yong’s Wukong Ranking List

    Time Limit:1000ms
    Case Time Limit:1000ms
    Memory Limit:512MB

    Description

    Jin Yong was the most famous and popular Chinese wuxia (The one who fight bad people by his Wukong i.e. Wushu and Kongfu) novelist who lived in Hong Kong. Between 1955 and 1972, he wrote 14 novels which earned him a reputation as one of the greatest and most popular Chinese writers. Over 100 million copies of his works have been sold worldwide,not including a countless number of pirated copies. Jin Yong’s works seem to have magic. Once you begin to read a novel of his, you just can’t stop until you finish it.

    Last month, Jin Yong passed away at the age of 94. Many Jin Yong’s fans in PKU held a meeting to memorize him. Jin Yong’s fans always like to discuss or argue or even quarrel about whose Wukong are better among the wuxia characters of his novel. During the meeting, this happened again:

    Every fans said some words like "Qiao Feng's Wukong is better than Guo Jing's". Obviously, those words may contradict each other and then cause quarrels. As a boring and girlfriendless male programmer of EECS school, you always want to make some things. So you are eager to point out the contradictions as soon as possible. That means, you want to find out the first one whose words contradict the words said by others before him.

    Please note that if A is better than B, and B is better than C, then of course A must be better than C.

    Input

    There are no more than 15 test cases.

    For each test case:

    The first line is an integer n( 1 <= n <=20), meaning that there are n sentences.

    The following n lines are those n sentences which is in the format below:

    s1 s2

    This means someone said that s1's Wukong was better than s2's. Both s1 and s2 are names of Jin Yong's characters which consists of only English letters. It's guaranteed that s1 and s2 are different, and their length is no more than 30. Names are case sensitive.

    Output

    For each test case, print the first sentence which cause a contradiction. If there are no contradiction, print 0 instead.

    Hint

    DON'T try to figure out who are those names in the sample and waste your time.

    Sample Input
    2
    BrokenReputation ExtinctNun
    HelloLaught EnvelopeNotFlat
    6
    LandOverWind LonelyLight
    FireMonk CutTheForest
    CutTheForest LookCrazy
    MakeFoxRush LetMeGo
    HeroAunt UniqueLand
    LookCrazy FireMonk
    Sample Output
    0
    LookCrazy FireMonk

    题意就是第一个人比第二个人厉害,问你从哪一句开始与上面的语句矛盾,闭包传递,有人是用dfs写的,有人是用floyd写的,我是用递归写的。

    代码:

     1 //A-传递闭包-递归 or 有向图floyd
     2 //看清楚题意,读错题了。。。
     3 #include<iostream>
     4 #include<cstdio>
     5 #include<cstring>
     6 #include<algorithm>
     7 #include<bitset>
     8 #include<cassert>
     9 #include<cctype>
    10 #include<cmath>
    11 #include<cstdlib>
    12 #include<ctime>
    13 #include<deque>
    14 #include<iomanip>
    15 #include<list>
    16 #include<map>
    17 #include<queue>
    18 #include<set>
    19 #include<stack>
    20 #include<vector>
    21 using namespace std;
    22 typedef long long ll;
    23 typedef long double ld;
    24 typedef pair<int,int> pii;
    25 
    26 const double PI=acos(-1.0);
    27 const double eps=1e-6;
    28 const ll mod=1e9+7;
    29 const int inf=0x3f3f3f3f;
    30 const int maxn=1e5+10;
    31 const int maxm=100+10;
    32 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    33 
    34 string s[50];
    35 
    36 bool Find(string y,string x,int pos)
    37 {
    38     for(int i=1;i<=pos;i+=2){
    39         if(s[i]==y){
    40             if(s[i+1]==x) return false;
    41             else return Find(s[i+1],x,pos);
    42         }
    43     }
    44     return true;
    45 }
    46 
    47 int main()
    48 {
    49     int n;
    50     while(cin>>n){
    51         for(int i=1;i<=2*n;i++)
    52             cin>>s[i];
    53         int flag=0,pos;
    54         for(int i=1;i<=2*n;i+=2){
    55             //cout<<Find(s[i+1],s[i],i-1)<<endl;
    56             if(!Find(s[i+1],s[i],i-1)){
    57                 flag=1;pos=i;break;
    58             }
    59             if(flag==1) break;
    60         }
    61         if(flag==1) cout<<s[pos]<<" "<<s[pos+1]<<endl;
    62         else cout<<0<<endl;
    63     }
    64 }
    65 */
    66 
    67 /*
    68 5
    69 b a
    70 c d
    71 d b
    72 a b
    73 b c
    74 
    75 
    76 
    77 a b
    78 */
  • 相关阅读:
    跨境电商ERP中的自动化 5.平台订单自动打印面单
    小特工具箱新增功能:文档转换、代码转换和AI写诗词
    跨境电商ERP中的自动化 4.平台订单自动取运单号
    C#.NET 使用HttpWebRequest发送JSON
    .net core .net5 asp.net core mvc 与quartz.net 3.3.3 新版本调用方式
    .NET CORE .NET5 控制台程序使用EF连接MYSQL
    C#.NET 国密SM3withSM2签名与验签 和JAVA互通
    JAVA RSA 私钥签名 公钥验证签名 公钥验签
    java 读取控制台输入
    C#.NET RSA 私钥签名 公钥验证签名
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9978844.html
Copyright © 2020-2023  润新知