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

Description2020 ICPC Asia Taipei-Hsinchu Site M. Keystroke(模拟)_第1张图片
Solution
模拟所有情况

Code

#include 
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;
}

你可能感兴趣的:(模拟)