P1 : Jin Yong’s Wukong Ranking List

Time Limit:1000ms
Case Time Limit:1000ms
Memory Limit:512MB

Description

Jin Yong was the most famous and popular Chinese wuxia (The one who fight bad people by his Wukong i.e. Wushu and Kongfu) novelist who lived in Hong Kong. Between 1955 and 1972, he wrote 14 novels which earned him a reputation as one of the greatest and most popular Chinese writers. Over 100 million copies of his works have been sold worldwide,not including a countless number of pirated copies. Jin Yong’s works seem to have magic. Once you begin to read a novel of his, you just can’t stop until you finish it.

Last month, Jin Yong passed away at the age of 94. Many Jin Yong’s fans in PKU held a meeting to memorize him. Jin Yong’s fans always like to discuss or argue or even quarrel about whose Wukong are better among the wuxia characters of his novel. During the meeting, this happened again:

Every fans said some words like "Qiao Feng's Wukong is better than Guo Jing's". Obviously, those words may contradict each other and then cause quarrels. As a boring and girlfriendless male programmer of EECS school, you always want to make some things. So you are eager to point out the contradictions as soon as possible. That means, you want to find out the first one whose words contradict the words said by others before him.

Please note that if A is better than B, and B is better than C, then of course A must be better than C.

Input

There are no more than 15 test cases.

For each test case:

The first line is an integer n( 1 <= n <=20), meaning that there are n sentences.

The following n lines are those n sentences which is in the format below:

s1 s2

This means someone said that s1's Wukong was better than s2's. Both s1 and s2 are names of Jin Yong's characters which consists of only English letters. It's guaranteed that s1 and s2 are different, and their length is no more than 30. Names are case sensitive.

Output

For each test case, print the first sentence which cause a contradiction. If there are no contradiction, print 0 instead.

Hint

DON'T try to figure out who are those names in the sample and waste your time.

Sample Input
2
BrokenReputation ExtinctNun
HelloLaught EnvelopeNotFlat
6
LandOverWind LonelyLight
FireMonk CutTheForest
CutTheForest LookCrazy
MakeFoxRush LetMeGo
HeroAunt UniqueLand
LookCrazy FireMonk
Sample Output
0
LookCrazy FireMonk

题意就是第一个人比第二个人厉害,问你从哪一句开始与上面的语句矛盾,闭包传递,有人是用dfs写的,有人是用floyd写的,我是用递归写的。

代码:

 //A-传递闭包-递归 or 有向图floyd
//看清楚题意,读错题了。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii; const double PI=acos(-1.0);
const double eps=1e-;
const ll mod=1e9+;
const int inf=0x3f3f3f3f;
const int maxn=1e5+;
const int maxm=+;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); string s[]; bool Find(string y,string x,int pos)
{
for(int i=;i<=pos;i+=){
if(s[i]==y){
if(s[i+]==x) return false;
else return Find(s[i+],x,pos);
}
}
return true;
} int main()
{
int n;
while(cin>>n){
for(int i=;i<=*n;i++)
cin>>s[i];
int flag=,pos;
for(int i=;i<=*n;i+=){
//cout<<Find(s[i+1],s[i],i-1)<<endl;
if(!Find(s[i+],s[i],i-)){
flag=;pos=i;break;
}
if(flag==) break;
}
if(flag==) cout<<s[pos]<<" "<<s[pos+]<<endl;
else cout<<<<endl;
}
}
*/ /*
5
b a
c d
d b
a b
b c a b
*/

hihoCoder #1870 : Jin Yong’s Wukong Ranking List-闭包传递(递归) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction A) 2018 ICPC 北京区域赛现场赛A的更多相关文章

  1. 「日常训练」Jin Yong’s Wukong Ranking List(HihoCoder-1870)

    题意与分析 2018ICPC北京站A题. 题意是这样的,给定若干人的武力值大小(A B的意思是A比B厉害),问到第几行会出现矛盾. 这题不能出现思维定势,看到矛盾就是矛盾并查集--A>B.A&g ...

  2. HihoCoder-1870 Jin Yong’s Wukong Ranking List(并查集)

    我发现大佬好像都是用拓扑排序写的(本菜鸡不会拓扑哭唧唧 说一下并查集的做法吧... 就是找两人右边的(辣鸡的那个人)那个是否比左边厉害,厉害的话就矛盾. 如果他俩没比较过就把厉害的并到辣鸡的. (辣鸡 ...

  3. 【最小割】【Dinic】HihoCoder - 1252 - The 2015 ACM-ICPC Asia Beijing Regional Contest - D - Kejin Game

    题意:有一个技能学习表,是一个DAG,要想正常学习到技能x,要将指向x的技能全部先学到,然后会有一个正常花费cx.然后你还有一种方案,通过氪金dx直接获得技能x.你还可以通过一定的代价,切断一条边.问 ...

  4. 【BFS】【枚举】HihoCoder - 1251 - The 2015 ACM-ICPC Asia Beijing Regional Contest - C - Today Is a Rainy Day

    题意:给你两个只由1~6组成的串,问你B串至少要经过几次操作变成A串. 一次操作要么选择一个种类的数,将其全部变成另一种类:要么选择一个数,将其变为另一个数. 可以证明,一定先进行一定数量的第一种操作 ...

  5. hihoCoder #1871 : Heshen's Account Book-字符串暴力模拟 自闭(getline()函数) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction B) 2018 ICPC 北京区域赛现场赛B

    P2 : Heshen's Account Book Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Description H ...

  6. hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people coul ...

  7. hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...

  8. hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...

  9. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

随机推荐

  1. C语言函数的变参实用与分析

    实现变参传递的关键是: 传入参数在内存中是连续分布的. #define va_list void* #define va_arg(arg, type) *(type*)arg; arg = (char ...

  2. 51Nod 1381 硬币游戏 | 概率(数学期望)

    Input 第一行给出一个整数T,表示有T组数据(1<=T<=10000). 第2行到T+1,每行给出一个整数R.(0< R <= 10,000,000,000) Output ...

  3. 【HNOI】五彩斑斓 模拟

    [题目描述] 给定一个n*m的矩阵,矩阵的某些位置有一个颜色(可以没有颜色,即为0),现在你可以将矩阵的某一行或者某一列染成同一种颜色,问最少用多少步能达到目标矩阵的染色方案,输出最少步数和方案. [ ...

  4. Java中的return语句使用总结

    Java中的return语句总是和方法有密切关系,return语句总是用在方法中,有两个作用,一个是返回方法指定类型的值(这个值总是确定的),一个是结束方法的执行(仅仅一个return语句).   在 ...

  5. Django rest framework 权限操作(源码分析)

    知识回顾http://www.cnblogs.com/ctztake/p/8419059.html 这一篇是基于上一篇写的,上一篇谢了认证的具体流程,看懂了上一篇这一篇才能看懂, 当用户访问是 首先执 ...

  6. chrome://settings/content

    chrome://settings/content C:\Users\用户名\AppData\Roaming\Microsoft\Internet Explorer chrome://version/

  7. java===java基础学习(13)---this,static(静态变量和静态方法)的使用

    package dog; public class PersonAndDog { public static void main(String[] args) { Dogs da_huang = ne ...

  8. selenium===splinter模块和selenium异曲同工

    学习文档: http://splinter.readthedocs.io/en/latest/ 安装以后用它来实现163邮箱的登陆操作:*和selenium一样,splinter同样需要对frame进 ...

  9. 工具安装===Sublime Text-安装

    Sublime Text 是一款通用型轻量级编辑器,支持多种编程语言.有许多功能强大的快捷键(如 Ctrl+d),支持丰富的插件扩展.如果平时需要在不同编程语言间切换,那么它将会是一个,不错的选择. ...

  10. C#调用Excel报 error CS1969: 找不到编译动态表达式所需的一个或多个类型。是否缺少引用?

    转自[http://blog.csdn.net/bodybo/article/details/43191319] 程序需要读取Exel文件,有如下代码段 object oMissing = Syste ...