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

时间:2022-09-12 19:50:49

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 *. 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 &num;1871 &colon; Heshen&&num;39&semi;s Account Book-字符串暴力模拟 自闭&lpar;getline&lpar;&rpar;函数&rpar; &lpar;ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction B&rpar; 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 【二分&plus;网络流&plus;优化】 &lpar;ACM-ICPC国际大学生程序设计竞赛北京赛区&lpar;2016&rpar;网络赛&rpar;

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

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

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

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

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

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

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

随机推荐

  1. MySQ中Lmax&lowbar;connections的合理设置

    max_connections 是指整个mysql服务器的最大连接数max_used_connections 是指每个数据库用户的最大连接数 MySQL服务器的连接数并不是要达到最大的100%为好,还 ...

  2. &lbrack;Leetcode&rsqb;&lbrack;Python&rsqb;41&colon; First Missing Positive

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 41: First Missing Positivehttps://oj.le ...

  3. 用Qt开发Web和本地混合的应用

    QtWebkit 模块使得Qt widget能够通过HTML的object标签嵌入到web页面中,并通过JavaScript代码进行访问,而Qt对象也能相应的访问web页面元素. 将Qt对象插入到we ...

  4. 使用Net&period;Mail、CDO组件、JMail组件三种方式发送邮件

    原文:使用Net.Mail.CDO组件.JMail组件三种方式发送邮件 一.使用Net.Mail 需要服务器认证,大部分服务器端口为25. { MailMessage mailMsg = mailMs ...

  5. StringUtils工具类常用方法汇总&lpar;判空、转换、移除、替换、反转&rpar;

    Apache commons lang3包下的StringUtils工具类中封装了一些字符串操作的方法,非常实用,使用起来也非常方便.最近自己也经常在项目中使用到了里面的一些方法,在这里将常用的方法总 ...

  6. 向文件写入一个数据块---write

    函数原型:ssize_t write(int fd,const void *buf,size_t count); 参数说明:fd:文件描述符,buf:写入数据的缓冲区,count:写入数据的最大长度. ...

  7. 使用 jQuery UI 和 jQuery 插件构建更好的 Web 应用程序

    简介: 对于那些使用 JavaScript 和 jQuery 库从桌面应用程序转向 Web 应用程序的开发人员来说,他们还不习惯去考虑应用程序基本的外观,因为这些以前都是由操作系统来处理的.了解 jQ ...

  8. ab 压测工具使用

    转自:http://www.cnblogs.com/lemtree/articles/1676641.html 就是APACHE自带的测试工具AB(apache benchmark).在APACHE的 ...

  9. Paper Reading - Convolutional Sequence to Sequence Learning &lpar; CoRR 2017 &rpar; &starf;

    Link of the Paper: https://arxiv.org/abs/1705.03122 Motivation: Compared to recurrent layers, convol ...

  10. hibernate 中对象的3种状态总结

    1.Hibernate把对象分文三种状态:Transient(临时状态).Persistent(持久化状态).Detached(游离状态). 1)Transient:刚刚new出来的对象,就是Tran ...