璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:usaco22open_subset_equality_s
problems
名称Subset Equality S
题目编号USACO22OPEN_S2
题目链接luogu.com.cn/…
来源USACO
算法分类预处理, 思维
难易程度一般般

Subset Equality S

想法

题目的突破点在'a'~'r'上。

预处理去掉2个字符的情况,最后去除任意字符可以通过去除2个字符的情况组合得出。

代码实现

#include<iostream>
#include<string>
#include<vector>
using namespace std;
 
bool F[30][30];
 
int main()
{
	string s, t;
	cin >> s >> t;
 
	for (int i = 0; i < 18; ++i) {
		for (int j = 0; j < 18; ++j) {
			char x = i + 'a', y = j + 'a';
			string temp_1, temp_2;
			for(auto c : s)
				if(c == x || c == y)
					temp_1 += c;
			for(auto c : t)
				if(c == x || c == y)
					temp_2 += c;
 
			if(temp_1 != temp_2)
				F[i][j] = false;
			else
				F[i][j] = true;
		}
	}
 
	int k;
	cin >> k;
	while(k--){
		string temp;
		cin >> temp;
		bool flag = true;
		for(auto i : temp)
			for(auto j : temp)
			{
				if(!F[i-'a'][j-'a'])
					flag = false;
			}
		if(flag)
			cout << "Y";
		else
			cout << "N";
	}
 
	return 0;
}
/app/www/public/data/pages/icpc/problems/usaco22open_subset_equality_s.txt · 最后更改: 2023/02/09 10:16 由 温婕莺