2020 年 “游族杯” 全国高校程序设计网络挑战赛【A&I 签到】

Problem A. Amateur Chess Players
Input file: standard input
Output file: standard output

Chess is a two-player board game played on a chessboard (a square-checkered board with 64 squaresarranged in an eight-by-eight grid). In a chess game, each player begins with sixteen pieces: one king, onequeen, two rooks, two knights, two bishops, and eight pawns. The object of the game is to checkmate theopponent’s king, whereby the king is under immediate attack (in “check”) and there is no way to removeor defend it from attack, or force the opposing player to forfeit.
2020 年 “游族杯” 全国高校程序设计网络挑战赛【A&I 签到】_第1张图片
Cuber QQ and Quber CC are two amateur chess players, who know almost nothing about all the fancyrules in chess, perhaps except how the chessboard looks like, and they have no interest in it. Instead, theyinvent their own chess game. At the beginning, Cuber QQ, who has the white pieces, and Quber CC, whohas the black pieces, place some of their pieces on the chessboard. Then they start to remove those piecesby turn. Cuber QQ moves first. In each turn, they must remove at least one of their own pieces (CuberQQ can only remove white and Quber CC can only remove black). Two or more pieces can be removedtogether in one turn if and only if these pieces are collinear on the chessboard, meaning they should liein the same line. Note that this line does NOT have to be in horizontal or vertical or diagnoal direction.The one who fails to make a move loses the game.
Now Cuber QQ and Quber CC are both desperate to win the game. So they will do it smartly and makeoptimal decisions. Who do you think will win the game, eventually?

Input
The input consists of four lines:
• The first line is an integer n (1 ≤ n ≤ 16), the number of white pieces on the chessboard.
• The second line consists of n space-separated positions, which are the positions of white pieces.
• The third line is an integer m (1 ≤ m ≤ 16), the number of black pieces on the chessboard.
• The last line consists of m space-separated positions, which are the positions of black pieces.
Each position is a upper case letter in “A” to “H”, followed by a digit in “1” to “8”.
It is guaranteed that there are no overlapping pieces, that is, all pieces are located at different positions.

Output
If Cuber QQ is going to win, output “Cuber QQ” without quotes. Otherwise output “Quber CC”.

Examples
2020 年 “游族杯” 全国高校程序设计网络挑战赛【A&I 签到】_第2张图片
题解:看谁先不能动。最优情况是一步只删一个,那么,比较两边的元素个数即可。

#include  
using namespace std;
int n,m;
char s[3];

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>s;
	cin>>m;
	for(int i=1;i<=m;i++) cin>>s;
	
	if(n>m) cout<<"Cuber QQ"<<endl;
	else cout<<"Quber CC"<<endl;
	
	return 0;
}

Problem F. Find / -type f -or -type d
Input file: standard input
Output file: standard output

Cuber QQ wants to know the number of files with extension .eoj in his computer. This can be easily
done with a command find / -type f | grep ’.eoj$’ | wc -l. However, Cuber QQ is a grep-hater,
who would rather write his own program than using grep. So he decides to take a detour: what if the
command starts with something else? Is it still possible to recover the results?
If you are not familiar with command usages in Linux, all you need to know is that ls and find are two
easy-to-use commands to inspect files and subdirectories a directory contains. For example, when you aretrying to get a list of everything in your computer, you might try to use: find / -type f -or -type d,which will give you a list like:
2020 年 “游族杯” 全国高校程序设计网络挑战赛【A&I 签到】_第3张图片

To make the problem even more interesting, Cuber QQ adds another shuf after find, so that the list
is shuffled into a random order and his secrets will stay covered. Cuber QQ is wondering whether it’s
possible to write a program cuber-qq-grep that filters out all the files with extension .eoj from the
given shuffled list, which is his initial intention. Still, instead of giving the filtered list directly, Cuber QQwants to know the length of this list, i.e., the number of files found. In other words, the following twocommands will be almost equivalent:

• find / -type f | grep ’.eoj$’ | wc -l
• find / -type f -or -type d | shuf | cuber-qq-grep

Well, there can be some subtle differences in input/output formats, but that’s not essential.
One more thing, on your file system, directory is only a logical concept. This means, a directory is createdonly when there is a file which relies on this directory is created and a directory cannot exist without files.TL;DR, given the randomly shuffled list of all directories and files on a computer, count the number offiles that ends with .eoj.

Input
The input starts with a line of one number n (1 ≤ n ≤ 105
), which is the length of the following list.
In the following n lines, each line contains one string, which is an absolute path to a file or a directory.
The path starts with /, and is composed of multiple tokens (file names and directory names) concatenatedwith /. The tokens always start with a lowercase letter, followed by no more than 9 lowercase letters ordots. The root folder alone will not be included in this list.It is guaranteed that the total length of n lines will be no longer than 106.

Output
Output the number of files satisfying the above-mentioned condition, in one line.

Examples
2020 年 “游族杯” 全国高校程序设计网络挑战赛【A&I 签到】_第4张图片
题解:其实问最末端(末端:换个说法,叶子节点)扩展名为 .eoj 有几个,然鹅不需要建树,快排一下,当前这一行最后有 .eoj,要是下一行不是它母串,答案 +1。【这里用到了 “双指针算法”,刚好前几天有总结过 两大类 “双指针” 算法剖析【附例题详解+AC代码】】

#include  
using namespace std;

int n;
string s[100005];

int check(string a,string b)
{
	int len1=a.size(), len2=b.size();
	
	if(len1 >= len2) return 0;
	
	int f=0;
	for(int i=0;i<len1;i++)
	    if(a[i]!=b[i]) {f=1;  break;}
	    
	return !f;
}

int main()
{
    cin>>n;

	for(int i=1;i<=n;i++) cin>>s[i];
	sort(s+1,s+1+n);
	
	int ans=0;
	for(int i=1,j; i<=n; i=j)
	{
		j=i+1;
		while(check(s[j-1],s[j]) && j<=n) j++;
		int len=s[j-1].size()-1;
		if(s[j-1][len]=='j' && s[j-1][len-1]=='o' && s[j-1][len-2]=='e' && s[j-1][len-3]=='.') ans++;
	}
	    
	cout<<ans<<endl;
	return 0;
}

Problem I. Idiotic Suffix Array
Input file: standard input
Output file: standard output

Cuber QQ did not know about the Suffix Array before, now he knows. So he eagerly wants to teach you.
2020 年 “游族杯” 全国高校程序设计网络挑战赛【A&I 签到】_第5张图片

Now he takes a string containing only lowercase letters as an example and builds a Suffix Array with thefollowing C++ code on a supercomputer.

std::vector build(const std::string& s) {
std::vector > suffixes;
for (size_t i = 0; i < s.length(); ++i) {
suffixes.emplace_back(s.substr(i), i);
}
std::sort(suffixes.begin(), suffixes.end());
std::vector sa(s.length());
for (size_t i = 0; i < s.length(); ++i) {
sa[i] = suffixes[i].second;
}
return sa;
}

For example, the Suffix Array of “ecnu” is {1, 0, 2, 3} and the Suffix Array of “cubercsl” is
{2, 5, 0, 3, 7, 4, 6, 1}.
It’s definitely not satisfying enough for Cuber QQ to show off his algorithm skills, so he wants to test youwith a problem.
He will give you two integers n and k (1 ≤ k ≤ n), you are required to answer him a string of length
n containing only lowercase letters and satisfying sa[k - 1] == 0, where sa is the Suffix Array of the
string built by the code above.
TL;DR, you are required to answer a string of length n containing only lowercase letters and it ranks k-thsmallest among all its suffixes in lexicographical order.
We can show that an answer always exists.
A string a is lexicographically smaller than a string b if and only if one of the following holds:

• a is a prefix of b, but a = b;
• in the first position where a and b differ, the string a has a letter that appears earlier in the alphabetthan the corresponding letter in b.

Input
Two integers n, k (1 ≤ k ≤ n ≤ 105) — the length of the string and the rank of the string itself among allits suffixes.

Output
Output the answer, which is a string of length n only containing lowercase letters.
If there are multiple answers, print any of them.

Examples
在这里插入图片描述
题解:后缀数组里面的 SA[i] 表示从i ~ n的后缀,排个序,k-1 ~ n,必须是字典序最小的。

#include 
using namespace std;
string s;

int main()
{
    int n,k,i;
	cin>>n>>k;
	
	for(i=1;i<=n;i++)
	{
		if(i==k)       s += 'c';
		else if(i<k)   s += 'e';
		else           s += 'n';
	}
	
	cout<<s<<endl;
	return 0;
}

你可能感兴趣的:(题解,模拟,分治&指针算法,算法)