zoukankan      html  css  js  c++  java
  • Gym-101873D Pants On Fire(Warshall算法)

    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 areexporting 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?

    Input

    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.

    Output

    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.

    Sample Input 1

    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

    Sample Output 1

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

    思路

    简单的 Warshall 算法求传递闭包

    Code

    #include <iostream>
    #include <map>
    #include <string>
    #include <stdio.h>
    using namespace std;
    
    int n, m;
    map<string, int> mp;
    string s1, s2, s3, s4, s5;
    const int maxn=205;
    bool a[maxn][maxn];
    void Warshall()
    {
         for (int k = 1; k <= 200; ++k)
            for (int i = 1; i <= 200; ++i)
                for (int j = 1; j <= 200; ++j)
                    a[i][j] |= (a[i][k] & a[k][j]);
    }
    int main()
    {
        std::ios::sync_with_stdio(0);
        cin >> n >> m;
        int idex = 0;
        for (int i = 0; i < n; i++)
        {
            cin >> s1 >> s2 >> s3 >> s4 >> s5;
            if (mp[s1] == 0)
                mp[s1] = ++idex;
            if (mp[s5] == 0)
                mp[s5] = ++idex;
            a[mp[s5]][mp[s1]] = 1;
        }
        Warshall();
        for (int i = 0; i < m; i++)
        {
            cin >> s1 >> s2 >> s3 >> s4 >> s5;
            int n1 = mp[s1];
            int n2 = mp[s5];
            if (a[n2][n1])
                puts("Fact");
            else if (a[n1][n2])
                puts("Alternative Fact");
            else
                puts("Pants on Fire");
        }
        return 0;
    }
    
  • 相关阅读:
    word转HTML并使用于浏览器界面
    配置wampserver出现服务器错误问题
    SVN使用及配置pycharm、本地Linux虚拟机教程
    加载本地json文件,调试出现 Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.解决方法
    转载:有关Html中<a>、<link>和<script>标签中相对路径与绝对路径的问题总结
    asp.net 登出设置
    Maven依赖中的scope详解
    什么情况下用resultType和 resultMap
    修改tomcat默认端口号8080
    SpringMVC
  • 原文地址:https://www.cnblogs.com/YY666/p/11390709.html
Copyright © 2011-2022 走看看