!
时间限制:1000ms
单点时限:1000ms
内存限制:512MB
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.
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.
For each test case, print the first sentence which cause a contradiction. If there are no contradiction, print 0 instead.
DON’T try to figure out who are those names in the sample and waste your time.
样例输入
2
BrokenReputation ExtinctNun
HelloLaught EnvelopeNotFlat
6
LandOverWind LonelyLight
FireMonk CutTheForest
CutTheForest LookCrazy
MakeFoxRush LetMeGo
HeroAunt UniqueLand
LookCrazy FireMonk
样例输出
0
LookCrazy FireMonk
给你人名 代表前者比后者强 求第一个出现错误的地方 人物强弱满足传递性,A > B,B > C,A > C
签到题,直接 map 映射一下hash 你会发现永远是小的数字比大的数字厉害,所以,当出现大的数字比小的数字厉害的时候就是第一个错误点,太水了,我还在想什么拓扑排序啥的,懵了半天,哈哈
#include
using namespace std;
map<string,int>m1;
int main()
{
int n;
while(cin>>n)
{
m1.clear();
int tot = 1;
int flag = 0;
string ans1 ,ans2;
for(int i=0;i<n;i++)
{
string s1,s2;
cin>>s1>>s2;
if(!m1[s1]) m1[s1] = tot++;
if(!m1[s2]) m1[s2] = tot++;
if(m1[s1]>=m1[s2]&&flag==0)
{
flag = 1;
ans1 = s1;
ans2 = s2;
}
}
if(!flag) cout<<0<<endl;
else cout<<ans1<<" "<<ans2<<endl;
}
}#include<bits/stdc++.h>
using namespace std;
map<string,int>m1;
int main()
{
int n;
while(cin>>n)
{
m1.clear();
int tot = 1;
int flag = 0;
string ans1 ,ans2;
for(int i=0;i<n;i++)
{
string s1,s2;
cin>>s1>>s2;
if(!m1[s1]) m1[s1] = tot++;
if(!m1[s2]) m1[s2] = tot++;
if(m1[s1]>=m1[s2]&&flag==0)
{
flag = 1;
ans1 = s1;
ans2 = s2;
}
}
if(!flag) cout<<0<<endl;
else cout<<ans1<<" "<<ans2<<endl;
}
}
ps :
这个真的得说在现场系列了,当时把题看完队友老哥直接上去就AC了。过两天有时间的写个退役总结