2022 Jiangsu Collegiate Programming Contest

A - PENTA KILL!

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 n𝑛 (1≤n≤10001≤𝑛≤1000), indicating the number of kills in the game.

Each of the following n𝑛 lines contains two strings a𝑎 and b𝑏 consisting of English letters and digital numbers, indicating that the player named a𝑎 kills the player named b𝑏. 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.

Examples

InputcopyOutputcopy
10
Bin Guigo
Grevthar Bin
GALA Grevthar
GALA TitaN
GALA Guigo
GALA Aegis
GALA Jojo
GALA Grevthar
Xiaohu Grevthar
GALA Aegis
PENTA KILL!
InputcopyOutputcopy
7
GALA Jojo
GALA Jojo
Aegis GALA
GALA Grevthar
GALA Aegis
GALA Guigo
GALA TitaN
PENTA KILL!
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.

思路:这题其实就是一个暴力,然后 要求得就是一个人连续的杀五个不同的人就算五杀(ps:队友说和该游戏的五杀机制还不一样,所以当时考虑的很复杂,但其实根本没有那么复杂)我们想的就是用map的键存名字,用unordered_set存击杀名字,然后满五就可以了,但是如果当前没有满五,但是现在杀的人之前已经杀过了,那就要从第一个不重复的名字开始重新计数。我们当时一直想的是直接清零计一重新计算,所以错了很多次。需要提醒一下的就是unordered_set是头插法。

#include "bits/stdc++.h"
using namespace std;
map<string , unordered_set<string> > mp;
int main(){
	int n;
	cin>>n;
	string a, b;
	while(n--){
		cin>>a>>b;
		if(mp[a].find(b) == mp[a].end()) mp[a].insert(b);
		else if(mp[a].size() != 5){
			auto t = mp[a].find(b);
			mp[a].erase(t, mp[a].end());
			mp[a].insert(b);
		}  
		 
	}
	for(auto i : mp){
		if(i.second.size() == 5) {
			cout<<"PENTA KILL!"<<endl;
			return 0;
		}
	}
	cout<<"SAD:("<<endl;
	return 0;
}

I.Cutting Suffix

Given a string S𝑆 of length n𝑛 consisting of lowercase English characters. We denote SuffixiSuffix𝑖 as the suffix of S𝑆 starting from the i𝑖-th character. We define wi,j𝑤𝑖,𝑗 as the length of the LCP of SuffixiSuffix𝑖 and SuffixjSuffix𝑗. LCP is the longest common prefix of two strings. For example, the LCP of abcaabca and abdabd is abab.

You should divide the integers from 11 to n𝑛 into two non-empty complementary sets T1,T2𝑇1,𝑇2. We define the value of this partition as follows.

∑i∈T1∑j∈T2wi,j∑𝑖∈𝑇1∑𝑗∈𝑇2𝑤𝑖,𝑗

Please find a partition to minimize the value.

Input

The input contains a string S𝑆 of length n𝑛 (2≤n≤1052≤𝑛≤105) in a single line, consisting of only lowercase English letters.

Output

Output a single integer indicating the minimum value.

Examples

InputcopyOutputcopy
aa
1
InputcopyOutputcopy
ab
0

思路:思维题,队长说所有一样的就可以取一个和剩下的,有不一样的就是0

#include "bits/stdc++.h"
using namespace std;
int main(){
	string s;
	cin>>s;
	int flag = 0;
	for(int i = 1;i < s.length(); i ++){
		if(s[i] != s[0]) flag = 1;
	}
	if(flag) cout<<0;
	else cout<<s.length() - 1;
	return 0;
}

K - aaaaaaaaaaA heH heH nuN

  

Vasily Tadokorov is a stringologist. He thinks a string is fragrant if it can be divided into two parts: nunhehheh as the prefix and a number of (excluding 00) a as the suffix. For example, nunhehhehaaaaaa is fragrant, but nunhehheh and nunhehhehoooaaa are not fragrant.

Today Vasily Tadokorov has some strings consisting of lowercase English letters. For each string, he wants to know how many subsequences of this string are fragrant. A string a𝑎 is a subsequence of a string b𝑏 if a𝑎 can be obtained from b𝑏 by deletion of several (including 00) characters.

The above is a problem of string that Vasily came up with. As we know, a problem usually has several examples for better understanding. However, Vasily gets buried in making some fragrant examples. After 2000 years, he finally makes two perfect examples as follows.

Example 1:

  • Input: nunhehhehahaahahahahahahaahaahahahahhanunhehhehahaahahahahahahaahaahahahahha
  • Output: 114514114514

Example 2:

  • Input: nunhehhehhehhahaahahahaahaahahaaaahaanunhehhehhehhahaahahahaahaahahaaaahaa
  • Output: 19198101919810

Vasily is not clever enough. He doesn't want to work for another 2000 years, so he asks you for help. He gives you T𝑇 tasks, each of which contains an integer n𝑛, and you should construct a string consisting of only lowercase English letters that has exactly n𝑛 fragrant subsequences.

Input

The first line contains an integer T𝑇 (1≤T≤10001≤𝑇≤1000), denoting the number of tasks.

Each of the next T𝑇 lines contains an integer n𝑛 (0≤n≤1090≤𝑛≤109).

Output

For each test case, output one string consisting of only lowercase English letters in a single line indicating the answer. You need to ensure that the sum of the length over all the output strings does not exceed 106106. It can be proved that a solution always exists. If there are multiple solutions, print any.

Examples

InputcopyOutputcopy
2
114514
1919810
nunhehhehahaahahahahahahaahaahahahahha
nunhehhehhehhahaahahahaahaahahaaaahaa

思路:这题是玥佬读得题,然后给了公式,然后我完善了一下,其实就是一个求公式的题目,网上的题解说什么二进制啥的,我没有看,大概就是求一个公式的解,反正解很多,用什么方法都一样 。然后就是不用担心没有解,题目给你了,相信姐,一定会有解。

#include "bits/stdc++.h"
#define int long long
using namespace std;


int a[50];
void f(){
	int t = 1;
	for(int i = 0; i < 50; i ++){
		a[i] = t;
		t <<= 1;
	}
}
signed main(){
	f();
	int T;
	cin>>T;
	while(T--){
		int n;
		cin>>n;
		int m = n;
		int summ = 0;
		vector<int> v;
		string s= "nunhehheh";
		int nn = s.length();
		int ans = 0;
		while(1){
			ans ++;
//			if(n == 1) break;
//			if(ans == 30) break;
//			cout<<n<<" "<<summ<<" "<<m<<endl;
			if(summ >= m ) break;
			int *t = upper_bound(a, a + 32, n + 1);
			int tt = t - a - 1;
			n -= (a[tt] - 1);
			v.push_back(tt);
			summ = summ + a[tt] - 1;
		}
//		cout<<v[0]<<endl;
		if(v.size() == 0) cout<<s;
		else {
				for(int i = 0; i < v[0]; i ++){
				s += 'a';
				}
				for(int i = 1; i < v.size(); i ++){
					v[i] = v[0] - v[i] + nn;
				}
				int k = 1;
				for(int i = 0;i < s.length(); i ++){
					while(k < v.size() && i == v[k] )  
						cout<<"h", k ++;
					cout<<s[i];
				}
		}
		
		if(T != 0) cout<<endl;
	}
	
//	cout<<t - a - 1<<endl;
		
	return 0;
}

L - Collecting Diamonds

 Gym - 103743L 

Our best explorer, Vingying, finds a deep cave that is full of diamonds! Well, he is a very careful man, so he decides to do some research before collecting them.

The diamonds can be divided into three kinds, noted as A,B,CA,B,C for convenience. There are a total of n𝑛 diamonds in a row, which can be regarded as a sequence s1,s2,…,sn𝑠1,𝑠2,…,𝑠𝑛 from left to right. Vingying will perform the operation several times, which consists of the following three steps in order.

  1. Choose an index i𝑖 (1≤i≤n−21≤𝑖≤𝑛−2) satisfying si=A𝑠𝑖=A, si+1=B𝑠𝑖+1=B, si+2=C𝑠𝑖+2=C.
  2. If the index is odd, then collect si𝑠𝑖 and si+2𝑠𝑖+2; otherwise, collect si+1𝑠𝑖+1.
  3. Update n𝑛 to the number of diamonds left and reindex the diamonds.

For example, s=ABCABC𝑠=ABCABC. We can choose index 11 and collect 1,31,3, then s𝑠 becomes BABCBABC indexed 1,2,3,41,2,3,4. But if we choose index 44 and collect 55, then s𝑠 becomes ABCACABCAC indexed 1,2,3,4,51,2,3,4,5.

Vingying wants to know the maximum number of operations (not the diamonds) he can do.

Input

The input contains a string consisting of only A,B,CA,B,C representing the sequence of the diamonds. The length of the string won't exceed 2×1052×105.

Output

Output a single integer representing the maximum number of operations.

Examples

InputcopyOutputcopy
ABCAAABCCC
2
InputcopyOutputcopy
AABCAAABCCC
4

思路:这题其实一早就看出来,其实就是首先删AC,然后剩最后一个了,最好删B,因为删AC有可能两边正好是AC就能继续删,但是删了B的话就没法继续了,但是如果是删了AC的话,剩下的A就是偶数位了,所以要删一个前面的B才能继续删A,这样的话就是我们最后一个最好删B的原因。那这样的话,一直想下去就能通过贪心得到我们问题的解,所以我们要构造的就是B的位置,B前面有几个可删的B,B的两边有几个AC,这样的话,我们就能最终求解答案。然后这里的话是参考了大佬的公式,我们没推出来那个贪心的公式。

2022 Jiangsu Collegiate Programming Contest「A模拟」「B 优先队列优化dp」「I 思维」「J 记忆化+暴力打表」「K 二进制构造」「L 思维」-CSDN博客

#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> PII;
vector<PII> v;
int main(){
	string s;
	cin>>s;
	for(int i = 0; i < s.length(); i ++){
		if(s[i] != 'B') continue;
		int l = i, r = i;
		while(l >= 1 && s[l - 1] == 'A') --l;
		while(r <= s.length() - 2 && s[r + 1] == 'C' ) ++r;
		if(min(i - l, r - i)) v.push_back({min(i - l, r - i), i % 2}); 
	}
	int ans = 0, num = 0;
 	for(auto i : v)
	{
		int x = i.first;
		int y = i.second;
		if(num == 0){
			if(y == 1) 
				if(x == 1) ans ++;
				else ans += 2, num ++;
			else ans ++, num ++;
		}
		else {
			ans += min(x, (y == 1) + num + 1);
			num ++;
		}
		
	}
	cout<<ans<<endl;
	return 0;
}

  • 24
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小竹子14

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值