2020 ICPC Asia Taipei-Hsinchu Site M. Keystroke(模拟)

博客围绕问题展开,包含问题描述、解决方案,重点在于模拟所有情况来解决问题,可能涉及信息技术领域的模拟算法等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description在这里插入图片描述
Solution
模拟所有情况

Code

#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int T;scanf("%d",&T);
	while(T--) {
		int m,n;scanf("%d %d",&m,&n);
		bool r[4], c[4];
		clr(r,false);clr(c,false);
		for(int i = 0;i < m;++i) {
			int x;scanf("%d",&x);r[x] = true;
		}for(int i = 0;i < n;++i) {
			int x;scanf("%d",&x);c[x] = true;
		}int res = 0;
		int k1 = 1, k2 = 2,k3 = 4,k4 = 8;
		for(int s = 0;s < (1<<4);++s) {
			bool flag = true;
			bool tmp1[4], tmp2[4];
			clr(tmp1,false);clr(tmp2,false);
			if(s&k1) tmp1[0] = tmp2[0] = true;
			if(s&k2) tmp1[0] = tmp2[1] = true;
			if(s&k3) tmp1[1] = tmp2[0] = true;
			if(s&k4) tmp1[1] = tmp2[1] = true;
			for(int i = 0;i < 2;++i) if(tmp1[i] != r[i]) {flag = false;break;}
			for(int i = 0;i < 2;++i) if(tmp2[i] != c[i]) {flag = false;break;}
			if(flag) res++;
		}printf("%d\n", res);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值