SDUT 2022 Spring Individual Contest(for 21) - 10 - Virtual Judge
OLO's global tournament, ISM, is in full swing and Shizuku is a big fan of GNR which is taking part in the tournament. OLO is a game where two teams of five players play against each other. PENTA KILL is considered an unbelievable achievement in the game, which means one player kills five pairwise distinct opponents in a row. We assume that a player will be resurrected immediately after his death, and the death will not affect the verdict of his PENTA KILL.
Normally, PENTA KILL will be displayed in the game. However, sometimes due to unintended disparity in latency between competing teams, it is not displayed properly in the game. After the game, Shizuku gets a chronological list of kills during the game. She wants to know whether a player has achieved PENTA KILL in this game.
Input
The first line contains an integer nn (1\le n \le 10001≤n≤1000), indicating the number of kills in the game.
Each of the following nn lines contains two strings aa and bb consisting of English letters and digital numbers, indicating that the player named aa kills the player named bb. The length of each string won't exceed 100100. It is guaranteed that there are no kills between teammates and there are exactly five players per team.
Output
Output PENTA KILL! if a player has achieved PENTA KILL, or SAD:( otherwise.
Sample 1
Inputcopy | Outputcopy |
---|---|
10 Bin Guigo Grevthar Bin GALA Grevthar GALA TitaN GALA Guigo GALA Aegis GALA Jojo GALA Grevthar Xiaohu Grevthar GALA Aegis |
PENTA KILL! |
Sample 2
Inputcopy | Outputcopy |
---|---|
7 GALA Jojo GALA Jojo Aegis GALA GALA Grevthar GALA Aegis GALA Guigo GALA TitaN |
PENTA KILL! |
Sample 3
Inputcopy | Outputcopy |
---|---|
7 GALA Jojo Aegis Ming GALA Grevthar GALA Grevthar GALA Aegis GALA Guigo GALA TitaN |
SAD:( |
Note
In the second sample, GALA kills Jojo, Grevthar, Aegis, Guigo, and TitaN in a row so he gets PENTA KILL.
In the third sample, GALA kills Grevthar twice after he kills Jojo so he doesn't kill five distinct opponents in a row.
map解法:
#include
using namespace std;
mapm;
mapm2;
string s1[1100];
string s2[1100];
int n,flag;
bool st[1100];
int main()
{
scanf("%d",&n);
for(int i=0;i>s1[i];
cin>>s2[i];
m[s1[i]]++;
}
// for(int i=0;i=5)
{
for(int j=i; j1)
{
m2[s2[j]]--;
if(m2.size()<5)
{
m2.clear();
break;
}
else
{
break;
}
}
}//不知道为啥,}放这就对了
// cout<=5)
{
flag=1;
}
}
}
// printf("%d\n",m2.size());
if(flag)
printf("PENTA KILL!\n");
else
printf("SAD:(\n");
}
set解法:
#include
using namespace std;
int main()
{
int n;
cin >> n;
string a[n + 1], b[n + 1];
map s;
for (int i = 0; i < n; i ++ )
{
cin >> a[i] >> b[i];
s[a[i]] ++;
}
bool flag = false;
for (int i = 0; i < n; i ++ )
{
if(s[a[i]] < 5) continue;
else
{
set v;
for (int j = i; j < n; j ++ )
{
if(a[j] == a[i])
{
if(v.find(b[j]) == v.end())
v.insert(b[j]);
else if(v.find(b[j]) != v.end() && v.size() >= 5)
{
break;
}
else if(v.find(b[j]) != v.end() && v.size () < 5)
{
v.clear();
break;
}
}
}
if(v.size() >= 5){
flag = true;
}
}
}
if(flag){
cout << "PENTA KILL!" << endl;
}else{
cout << "SAD:(" << endl;
}
return 0;
}