Pants On Fire(链式前向星存图、dfs)
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;
}
Pants On Fire(链式前向星存图、dfs)的更多相关文章
- 最短路 spfa 算法 && 链式前向星存图
推荐博客 https://i.cnblogs.com/EditPosts.aspx?opt=1 http://blog.csdn.net/mcdonnell_douglas/article/deta ...
- C++算法 链式前向星存图
这个东西恶心了我一阵子,那个什么是什么的上一个一直是背下来的,上次比赛忘了,回来有个题也要用,只能再学一遍,之前也是,不会为什么不学呢.我觉得是因为他们讲的不太容易理解,所以我自己给那些不会的人们讲一 ...
- UESTC 30.最短路-最短路(Floyd or Spfa(链式前向星存图))
最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 在每年的校赛里,所有进入决赛的同 ...
- 链式前向星存树图和遍历它的两种方法【dfs、bfs】
目录 一.链式前向星存图 二.两种遍历方法 一.链式前向星存图:(n个点,n-1条边) 链式前向星把上面的树图存下来,输入: 9 ///代表要存进去n个点 1 2 ///下面是n-1条边,每条边连接两 ...
- UESTC30-最短路-Floyd最短路、spfa+链式前向星建图
最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 在每年的校赛里,所有进入决赛的同 ...
- POJ 1655 Balancing Act ( 树的重心板子题,链式前向星建图)
题意: 给你一个由n个节点n-1条边构成的一棵树,你需要输出树的重心是那个节点,以及重心删除后得到的最大子树的节点个数size,如果size相同就选取编号最小的 题解: 树的重心定义:找到一个点,其所 ...
- 链式前向星版DIjistra POJ 2387
链式前向星 在做图论题的时候,偶然碰到了一个数据量很大的题目,用vector的邻接表直接超时,上网查了一下发现这道题数据很大,vector可定会超的,不会指针链表的我找到了链式前向星这个好东西,接下来 ...
- POJ 3169 Layout(差分约束+链式前向星+SPFA)
描述 Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 ...
- poj-1459-最大流dinic+链式前向星-isap+bfs+stack
title: poj-1459-最大流dinic+链式前向星-isap+bfs+stack date: 2018-11-22 20:57:54 tags: acm 刷题 categories: ACM ...
随机推荐
- http://blog.itpub.net/28602568/viewspace-759789/
varchar .varchar2.nvarchar.nvarchar2 -->存储可变的字符串 varchar .varchar2:varchar:汉字全角等字符占2字节,数字.字母均1个字 ...
- search(16)- elastic4s-内嵌文件:nested and join
从SQL领域来的用户,对于ES的文件关系维护方式会感到很不习惯.毕竟,ES是分布式数据库只能高效处理独个扁平类型文件,无法支持关系式数据库那样的文件拼接.但是,任何数据库应用都无法避免树型文件关系,因 ...
- Poj1753 翻转棋子
这个题就是用枚举举遍所有情况,然后一个一个深搜看看是不是符合条件,符合条件直接退出,不符合则继续, 由于表格只有16个所以可以得知最多的步数只能是16,所以可以根据步数从0到16依次枚举, 第一个符合 ...
- dubbo分布式应用
dubbo介绍: dubbo是一款分布式服务框架,支持高性能和透明化的RPC远程服务调用方案,每天为2千多个服务提供大于30亿次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点以及别的公司的业务中. ...
- 对于近似有序序列(即除掉少数K个元素后是有序序列且K<<n),试分析直接插入排序,冒牌排序和简单选择排序的时间复杂度
学弟问的一道数据结构的题,关于一些排序算法的时间复杂度. 针对近似有序序列, ①当使用直接插入排序时,其基本操作为数组中元素的移动.最好情况下,待排序列有序,无需移动,此时时间复杂度为O(n), 当为 ...
- 【NLP】常用优化方法
目录 梯度下降法 动量法 AdaGrad算法 RMSProP算法 AdaDelta算法 Adam算法 1.梯度下降法 梯度下降法可以分为三种,批量梯度下降法(BGD).小批量梯度下降(MBGD).随机 ...
- Multisim-74LS08\74LS02\74LS86逻辑功能仿真实验
一. 实验目的 了解TTL门电路的外观封装.引脚分布和使用方法. 掌握数字电路试验台.万用表和示波器的使用方法. 掌握TTL与门.或非门和异或门的逻辑功能. 认识门电路对信号的控制作用. 二.实验内容 ...
- [256个管理学理论]002.青蛙效应(Frog Effect)
青蛙效应(Frog Effect) 从一个话题开始: 当下,社会发展突飞猛进,日新月异.在世界经济危机中,我国国民生产总值增长幅度始终在8%以上,引起世人的瞩目. 但,在国内时常也能听到广大投资者对股 ...
- nginx 搭建图片服务器(windows 下,linux 下原理应该一样)
作者的心声:很多知道的.用过的东西,不写下来,下次还要百度查询,浪费时间和精力,故本次写下学习笔记,方便下次查阅. 题外话:如有读者通过我这篇博客解决了工作上的难题,可以给个评论,让我一起分享你的喜悦 ...
- Rocket - debug - TLDebugModuleInner - COMMAND
https://mp.weixin.qq.com/s/Lz_D43YdhbRhiGiyoCBxDg 简单介绍TLDebugModuleInner中COMMAND寄存器的实现. 1. COMMANDRe ...