• 【闭包】Pants On Fire


    Pants On Fire

    题目描述

    Donald and Mike are the leaders of the free world and haven’t yet (after half a year) managed to start a nuclear war. It is so great! It is so tremendous!
    Despite the great and best success of Donald’s Administration, there are still a few things he likes to complain about.
    The Mexican government is much smarter, much sharper, and much more cunning.
    And they send all these bad hombres over because they don’t want to pay for them.
    They don’t want to take care of them.
    Donald J. Trump, First Republican Presidential Debate, August 6, 2015
    He also frequently compares Mexicans to other bad people (like Germans, since they are exporting so many expensive cars to the US). Due to the tremendous amount of statements he has made (mostly containing less than 140 characters ...) the “Fake-News” New York Telegraph (NYT) has to put in a lot of effort to clarify and comment on all the statements of Donald. To check a statement, they have a list of facts they deem to be true and classify Donald’s
    statements into three groups: real facts (which are logical conclusions from their list of true facts), exaggerations (which do not follow, but are still consistent with the papers list of facts),and alternative facts (which contradict the knowledge of the newspaper).
    They have asked you to write a program helping them to classify all of Donald’s statements –after all it is hard for a journalist to go through them all and check them all, right?

    输入

    The input consists of:
    • one line containing two integers n and m, where
    – n (1 ≤ n ≤ 200) is the number of facts deemed true by the NYT;
    – m (1 ≤ m ≤ 200) is the number of statements uttered by the Donald.
    • n lines each containing a statement deemed true by the NYT.
    • m lines each containing a statement uttered by the Donald.
    All statements are of the form a are worse than b, for some strings a and b, stating that a is (strictly) worse than b. The strings a and b are never identical. Both a and b are of length between 1 and 30 characters and contain only lowercase and uppercase letters of the English alphabet.
    Note that Donald’s statements may contain countries that the NYT does not know about. You may assume that worseness is transitive and that the first n lines do not contain any contradictory statement. Interestingly, Donald’s press secretary (Grumpy Sean) has managed to convince him not to make up countries when tweeting, thus the input mentions at most 193 different countries.

    输出

    For every of the m statements of Donald output one line containing
    • Fact if the statement is true given the n facts of the NYT
    • Alternative Fact if the inversion of the statement is true given the n facts of the NYT
    • Pants on Fire if the statement does not follow, but neither does its inverse.

    样例输入

    4 5
    Mexicans are worse than Americans
    Russians are worse than Mexicans
    NorthKoreans are worse than Germans
    Canadians are worse than Americans
    Russians are worse than Americans
    Germans are worse than NorthKoreans
    NorthKoreans are worse than Mexicans
    NorthKoreans are worse than French
    Mexicans are worse than Canadians
    

    样例输出

    Fact
    Alternative Fact
    Pants on Fire
    Pants on Fire
    Pants on Fire




    【题解】

    就是简单转递闭包,如果不存在关系返回Pants On Fire 即可,如果正向Fact  ,反向则为Alternative Fact

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int N = 2e2+10;
     4 unordered_map <string,int> Mp ;
     5 string n1,n2,are,worse,than;
     6 int G[N][N];
     7 int idx = 1 ;
     8 int n,m;
     9 int main()
    10 {
    11     ios_base :: sync_with_stdio(false);
    12     cin.tie(NULL), cout.tie(NULL) ;
    13   
    14     cin >> n >> m ;
    15     for(int i=0; i<n; i++)
    16     {
    17         cin >> n1 >> are >> worse >> than >> n2 ;
    18         if( Mp[n1] == 0 )   Mp[n1] = idx ++ ;
    19         if( Mp[n2] == 0 )   Mp[n2] = idx ++ ;
    20         G[Mp[n1]][Mp[n2]] = 1 ;
    21     }
    22     for(int k=1; k<idx; k++)
    23     {
    24         for(int i=1; i<idx; i++)
    25         {
    26             for(int j=1; j<idx; j++)
    27             {
    28                 if( G[i][k] == 1 && G[k][j] == 1 )
    29                 {
    30                     G[i][j] = 1 ;
    31                 }
    32             }
    33         }
    34     }
    35   
    36     for(int i=0; i<m; i++)
    37     {
    38         cin >> n1 >> are >> worse >> than >> n2 ;
    39         if( G[Mp[n1]][Mp[n2]] == 1 )
    40         {
    41             cout << "Fact"<<endl;
    42         }
    43         else if(G[Mp[n2]][Mp[n1]] == 1 )
    44         {
    45             cout << "Alternative Fact"<<endl;
    46         }
    47         else
    48         {
    49             cout << "Pants on Fire" <<endl;
    50         }
    51     }
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    树与树的表示
    队列的顺序/链式存储实现
    堆栈的链式存储实现
    堆栈的顺序存储实现
    线性表的链式存储求表长,查找,插入,删除
    C语言博客作业--函数
    C语言博客作业--嵌套循环
    C语言第三次博客作业---单层循环结构
    C语言第二次博客作业---分支结构
    C语言第一次博客作业——输入输出格式
  • 原文地址:https://www.cnblogs.com/Osea/p/11397620.html
Copyright © 2020-2023  润新知