璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:usaco22dec_reverse_engineering_b
problems
名称Reverse Engineering B
题目编号USACO22DEC_B3
题目链接luogu.com.cn/…
来源USACO
算法分类构造
难易程度一般般

Reverse Engineering B

想法

题目大意:构造处理过程,判断原输入与输出是否出现矛盾的地方。

判断的顺序可以任意调整,因为当可以通过该规则对给定的输入输出进行处理时,先处理该输入输出与后处理该输入输出是不影响的,如果这对输入输出可被其他规则处理时,该规则也不会影响其他输入输出。故可以直接通过输入输出对规则进行构造,无需考虑顺序问题。

题目要求判断是否出现矛盾,先假设没有矛盾,对所有的位与输入输出进行匹配检测,当出现同一位的输入匹配上一致输出,说明该位置存在该输入输出的规则。对规则进行构造,且将所有可以被该规则构造的输入输出删除。继续对剩余的输入输出进行规则构造。直到所有的输入输出全部删除,说明该组输入输出没有出现矛盾。如果枚举完所有的位且没有构造出任何规则,说明该输入输出存在矛盾。

代码实现

#include<iostream>
#include<string>
#include<vector>
using namespace std;
 
int main()
{
	int T;
	cin >> T;
	while(T--)
	{
		int n, m;
		cin >> n >> m;
		vector<int>d(m), b[m];
		vector<bool>del(m);
		string temp;
		for (int i = 0; i < m; ++i) {
			cin >> temp >> d[i];
			for (int j = 0; j < n; ++j) {
				b[i].push_back(temp[j] - '0');
			}
			del[i] = false;
		}
		int cnt = m;
		while(cnt != 0)
		{
			bool flag = false;
			for (int i = 0; i < n; ++i) { // 枚举每一位
				bool vis[2][2]={ {0, 0}, {0, 0} };
				for (int j = 0; j < m; ++j) { // 枚举每个询问
					if(del[j])continue;
					vis[b[j][i]][d[j]] = true;
				}
 
				if(vis[0][0] xor vis[0][1] )
				{
					for (int j = 0; j < m; ++j)
						if(b[j][i] == 0 && !del[j])
						{
							del[j] = true; cnt--; flag = true;
						}
				}
 
				if(vis[1][1] xor vis[1][0])
				{
					for (int j = 0; j < m; ++j)
						if(b[j][i] == 1 && !del[j])
						{
							del[j] = true; cnt--; flag = true;
						}
				}
			}
 
			if(!flag && cnt != 0)
			{
				cout << "LIE" << '\n';
				break;
			}
		}
 
		if(cnt == 0)
			cout << "OK" << '\n';
	}
 
	return 0;
}

板书

/app/www/public/data/pages/icpc/problems/usaco22dec_reverse_engineering_b.txt · 最后更改: 2023/06/13 05:33 由 温婕莺