A - PENTA KILL!

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

InputcopyOutputcopy
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

InputcopyOutputcopy
7
GALA Jojo
GALA Jojo
Aegis GALA
GALA Grevthar
GALA Aegis
GALA Guigo
GALA TitaN
PENTA KILL!

Sample 3

InputcopyOutputcopy
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<bits/stdc++.h>
using namespace std;
map<string,int>m;
map<string,int>m2;
string s1[1100];
string s2[1100];
int n,flag;
bool st[1100];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>s1[i];
        cin>>s2[i];
        m[s1[i]]++;
    }
//    for(int i=0;i<n;i++)
//    {
//        printf("%d\n",m[s1[i]]);
//    }
    for(int i=0;i<n;i++)
    {
        if(m[s1[i]]>=5)
        {
            for(int j=i; j<n; j++)
            {
                if(s1[j]==s1[i])
                {
                    m2[s2[j]]++;
//                }放这就错了
                    if(m2[s2[j]]>1)
                    {
                        m2[s2[j]]--;
                        if(m2.size()<5)
                        {
                            m2.clear();
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }//不知道为啥,}放这就对了
//                cout<<s2[j]<<endl;
            }
            if(m2.size()>=5)
            {
                flag=1;
            }
        }
    }
//    printf("%d\n",m2.size());
    if(flag)
       printf("PENTA KILL!\n");
    else
        printf("SAD:(\n");
}

set解法:

#include<bits/stdc++.h>
using namespace std;
int main()
{

	int n;
	cin >> n;
	string a[n + 1], b[n + 1];
	map<string, int> 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<string> 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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值