Pants On Fire
传送门:链接 来源:upc9653
题目描述
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
题目含义:
根据前n项输入的内容,判断后m项内容和前n项的一致性,输出矛盾、不矛盾、无法确定,三种结果。
思路:
开始用邻接矩阵写的,写一半写不下去了,仔细想想如果用邻接矩阵写最终还是要dfs,又想到之前写了个链式前向星存图加dfs/bfs的博客,就用链式前向星代替了临界矩阵,写完检查dfs的时候出错了,很低级的错误…
用字符串做id肯定不好操作,就用map给每个名字赋id值,然后链式前向星存图(单向边),最后dfs就行了。
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int MAX=3e2;
map<string,int>mp;
int cnt=1;
struct node{
int to;
int next;
}edge[MAX+5];
int getname(char name[])
{
if(mp[name]==0){
mp[name]=cnt;
return cnt++;
}else{
return mp[name];
}
}
int ans;
int head[MAX+5];
void init()
{
memset(head,-1,sizeof(head));
ans=0;
}
void addedge(int u,int v)
{
edge[ans].to=v;
edge[ans].next=head[u];
head[u]=ans++;
}
int aut[MAX+5][MAX+5];
int flag=0;
void dfs(int k,int v)
{
if(k==v||flag){
flag=1;
return ;
}
int flag=0;
for(int i=head[k];~i;i=edge[i].next){
int t=edge[i].to;
dfs(t,v);
}
}
int main()
{
int n,m;
cin>>n>>m;
init();
for(int i=0;i<n;i++){
char u[35],v[35],w[35],x[35],y[35];
cin>>u>>v>>w>>x>>y;
int id1=getname(y),id2=getname(u);
addedge(id1,id2);
}
for(int i=0;i<m;i++){
char u[35],v[35],w[35],x[35],y[35];
cin>>u>>v>>w>>x>>y;
int id1=getname(y);
int id2=getname(u);
//cout<<id1<<"***"<<id2<<endl;
flag=0;
dfs(id1,id2);
int num1=flag;
flag=0;
dfs(id2,id1);
int num2=flag;
//cout<<num1<<"***"<<num2<<endl;
if(num1==0&&num2==0) cout<<"Pants on Fire"<<endl;
else if(num1==0&&num2==1) cout<<"Alternative Fact"<<endl;
else if(num1==1&&num2==0) cout<<"Fact"<<endl;
}
return 0;
}