hihoCoder #1870 : Jin Yong’s Wukong Ranking List-闭包传递(递归) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction A) 2018 ICPC 北京区域赛现场赛A
P1 : Jin Yong’s Wukong Ranking List
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
- 2
- Sample Output
-
- 0
- LookCrazy FireMonk
- 0
题意就是第一个人比第二个人厉害,问你从哪一句开始与上面的语句矛盾,闭包传递,有人是用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的更多相关文章
- 「日常训练」Jin Yong’s Wukong Ranking List(HihoCoder-1870)
题意与分析 2018ICPC北京站A题. 题意是这样的,给定若干人的武力值大小(A B的意思是A比B厉害),问到第几行会出现矛盾. 这题不能出现思维定势,看到矛盾就是矛盾并查集--A>B.A&g ...
- HihoCoder-1870 Jin Yong’s Wukong Ranking List(并查集)
我发现大佬好像都是用拓扑排序写的(本菜鸡不会拓扑哭唧唧 说一下并查集的做法吧... 就是找两人右边的(辣鸡的那个人)那个是否比左边厉害,厉害的话就矛盾. 如果他俩没比较过就把厉害的并到辣鸡的. (辣鸡 ...
- 【最小割】【Dinic】HihoCoder - 1252 - The 2015 ACM-ICPC Asia Beijing Regional Contest - D - Kejin Game
题意:有一个技能学习表,是一个DAG,要想正常学习到技能x,要将指向x的技能全部先学到,然后会有一个正常花费cx.然后你还有一种方案,通过氪金dx直接获得技能x.你还可以通过一定的代价,切断一条边.问 ...
- 【BFS】【枚举】HihoCoder - 1251 - The 2015 ACM-ICPC Asia Beijing Regional Contest - C - Today Is a Rainy Day
题意:给你两个只由1~6组成的串,问你B串至少要经过几次操作变成A串. 一次操作要么选择一个种类的数,将其全部变成另一种类:要么选择一个数,将其变为另一个数. 可以证明,一定先进行一定数量的第一种操作 ...
- 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 ...
- hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people coul ...
- hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...
- hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...
随机推荐
- 使用freemarker生成word、html时图片显示问题
使用freemarker生成word.html时图片显示问题 博客分类: Java 使用freemarker生成word时图片显示问题使用freemarker生成html时图片显示问题使用iText生 ...
- Android 之 Spinner 键值对的绑定(转)
很多时候我们会在下拉菜单中绑定一个值,但是 Spinner本身不提供这样的服务 于是在网上找了N久,终于找到一个简单易用的方案;废话不多说,直接上菜了 首先要定义一个Item类,有以下要注意的: ...
- 【网络】RFC1245-OSPF Protocol Analysis
OSPF协议分析 摘要 这是OSPF协议的两份报告中的第一份,这些报告是因特网工程指导组要求的,是用来将一个因特网协议写成标准草案的.OSPF是一个TCP/IP协议族中的一个的路由协议,被设计用于一个 ...
- 51Nod 1083 矩阵取数问题 | 动态规划
#include "bits/stdc++.h" using namespace std; #define LL long long #define INF 0x3f3f3f3f3 ...
- UOJ#110. 【APIO2015】Bali Sculptures
印尼巴厘岛的公路上有许多的雕塑,我们来关注它的一条主干道. 在这条主干道上一共有 NN 座雕塑,为方便起见,我们把这些雕塑从 11 到 NN 连续地进行标号,其中第 ii 座雕塑的年龄是 YiYi 年 ...
- 【POJ】1830 开关问题(高斯消元)
http://poj.org/problem?id=1830 高斯消元无解的条件:当存在非法的左式=0而右式不等于0的情况,即为非法.这个可以在消元后,对没有使用过的方程验证是否右式不等于0(此时因为 ...
- E题hdu 1425 sort
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 sort Time Limit: 6000/1000 MS (Java/Others) M ...
- Python学习笔记 - day14 - Celery异步任务
Celery概述 关于celery的定义,首先来看官方网站: Celery(芹菜) 是一个简单.灵活且可靠的,处理大量消息的分布式系统,并且提供维护这样一个系统的必需工具. 简单来看,是一个基于pyt ...
- Linux下通过jstat命令查看jvm的GC情况
jstat命令可以查看堆内存各部分的使用量,以及加载类的数量.命令的格式如下: jstat [-命令选项] [vmid] [间隔时间/毫秒] [查询次数] 注意!!!:使用的jdk版本是jdk8. ...
- 无缝滚动Js
<html> <body> <div style="width: 190px; height: 127px; overflow: hidden; font-si ...