A. Computer Game【dfs诈骗】

A. Computer Game

image
image

代码

点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<cctype>
using namespace std;

#define X first
#define Y second

typedef pair<int,int> pii;
typedef long long LL;
const char nl = '\n';
const int N = 1e5+10;
const int M = 2e5+10;
int n,m;
int cnt[110];
void solve(){
	bool f = 1;
	memset(cnt,0,sizeof cnt);
	cin >> n;
	string s;
	for(int i = 1; i <= 2; i ++ ){
		cin >> s;
		for(int j = 0; j < n; j ++ ){
			if(s[j] == '1')cnt[j + 2] ++;
			if(i == 2 && cnt[j + 2] == 2){
				f = 0;
				break;
			}
		}
	}
	if(f)cout << "YES" << nl;
	else cout << "NO" << nl;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);

	int T;
	cin >> T;
	while(T --){
		solve();
	}
}

小结

  1. 惯性思维直接dfs导致tle
  2. 注意题目特性只有两行
  3. 注意不要重复定义,否则全局变量变局部变量
  4. 注意dfs最好没有返回值,用f记录一下是否能抵达就好,有返回值会特别乱
posted @ 2023-03-10 23:41  Keith-  阅读(25)  评论(0编辑  收藏  举报