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

利用传递闭包可以解决此类问题
传递闭包解释
今天有人提到了传递闭包,我简单说说吧。
所谓传递性,可以这样理解:对于一个节点i,如果j能到i,i能到k,那么j就能到k。求传递闭包,就是把图中所有满足这样传递性的节点都弄出来,计算完成后,我们也就知道任意两个节点之间是否相连。
传递闭包的计算过程一般可以用Warshell算法描述:
For 每个节点i Do
For 每个节点j Do
If j能到i Then
For 每个节点k Do
a[j, k] := a[j, k] Or ( a[j, i] And a[ i, k] )
其中a数组为布尔数组,用来描述两个节点是否相连,可以看做一个无权图的邻接矩阵。可以看到,算法过程跟Floyd很相似,三重循环,枚举每个中间节点。只不过传递闭包只需要求出两个节点是否相连,而不用求其间的最短路径长。

代码

#include<iostream>  //传递闭包 遇到谁比谁大的时候 
#include<map>
#include<cstring> 
using namespace std;
map<string,int> mp;
int cnt;
bool ok[500][500]; 
int main()
{
	int n,m;
	cin>>n>>m;
	string a,b,c,d,e;
	for(int i=1;i<=n;i++) 
	{
		cin>>a>>b>>c>>d>>e;
		if(!mp[a]) mp[a]=++cnt;
		if(!mp[e]) mp[e]=++cnt;
		ok[mp[a]][mp[e]]=true;
	}
	for(int k=1;k<=cnt;k++)   //传递闭包 
	{
		for(int i=1;i<=cnt;i++)
		{
			for(int j=1;j<=cnt;j++)
				ok[i][j]|=ok[i][k]&&ok[k][j];
		}
	}
	for(int i=1;i<=m;i++)
	{
		cin>>a>>b>>c>>d>>e;
		if(!mp[a]||!mp[e])
		{
		 puts("Pants on Fire");//什么都没有出现过
		 continue;
		}
		int u=mp[a],v=mp[e];
		if(ok[u][v]) puts("Fact") ;
		else if(ok[v][u]) puts("Alternative Fact");
		else puts("Pants on Fire");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值