首页 > 其他分享 >题解:CF1994B Fun Game

题解:CF1994B Fun Game

时间:2024-10-25 10:59:18浏览次数:1  
标签:ch return int 题解 while Game Fun mod define

涉及知识点:异或,字符串处理。

解题思路

‌异或是一种二进制运算,用于比较两个数字的差异。 当两个输入不同时,异或运算的结果为1;当两个输入相同时,结果为0。

现在就可以切掉本题了。

设两个字符串分别为 $a$,$b$。

  1. 如果 $a$ 和 $b$ 完全相同,输出 Yes
  2. 如果 $a$ 中没有 $1$ 且 $b$ 中没有 $1$,输出 Yes
  3. 如果 $a$ 中没有 $1$ 且 $b$ 中有 $1$,输出 No
  4. 如果 $a$ 中出现 $1$ 的第 $1$ 个位置比 $b$ 中出现 $1$ 的位置靠前,输出 No
  5. 其他情况输出 Yes

代码

#include <bits/stdc++.h>
#define int long long
#define ll __int128
#define db double
#define ldb long double
#define vo void
#define endl '\n'
#define il inline
#define re register
#define ve vector
#define p_q priority_queue
using namespace std;

//#define O2 1
#ifdef O2
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
#endif

namespace OI {
	template <typename T>
	il T read() {
		T x = 0, f = 1;
		int ch = getchar();
		while (!isdigit(ch)) {
			if (ch == '-') f = -1;
			ch = getchar();
		}
		while (isdigit(ch)) {
			x = (x << 3) + (x << 1) + (ch ^ 48);
			ch = getchar();
		}
		return x * f;
	}
	template <typename TE>
	il void write(TE x) {
		if (x < 0) {
			x = -x;
			putchar('-');
		}
		TE sta[35];
		int top = 0;
		do {
			sta[top++] = x % 10, x /= 10;
		} while (x);
		while (top) putchar(sta[--top] + '0');
	}
	il string read_with_string() {
		string s = "";
		char ch = getchar();
		while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')) {
			s += ch;
			ch = getchar();
		}
		return s;
	}
	il void write_with_string(string s) {
		for (int i = 0; i < s.size(); i ++ ) putchar(s[i]);
	}
}
namespace COMB {
	int fact[200000];
	int Triangle[1010][1010];
	void Fact(int n, int mod) {
		fact[0] = 1;
		for (int i = 1; i <= n; i ++ ) fact[i] = ((fact[i - 1]) % mod * (i % mod)) % mod;
	}
	void Pascal_s_triangle(int n, int mod) {
		for (int i = 0; i <= n; i ++ ) Triangle[i][0] = 1;
		for (int i = 1; i <= n; i ++ )
			for (int j = 1; j <= i; j ++ )
				Triangle[i][j] = (Triangle[i - 1][j] + Triangle[i - 1][j - 1]) % mod;
	}
	int pw(int x, int y, int mod) {
		int res = 1;
		while (y) {
			if (y & 1) res = ((res % mod) * (x % mod)) % mod;
			x = (x % mod) * (x % mod) % mod;
			y >>= 1;
		}
		return res;
	}
	int pw(int x, int y) {
		int res = 1;
		while (y) {
			if (y & 1) res *= x;
			x *= x;
			y >>= 1;
		}
	}
	int GCD(int x, int y, int mod) {
		return __gcd(x, y) % mod;
	}
	int LCM(int x, int y, int mod) {
		return (((x % mod) * (y % mod)) % mod / (GCD(x, y, mod) % mod)) % mod;
	}
	int C(int n, int m, int mod) {
		if (m > n || m < 0) return 0;
		return fact[n] * pw(fact[m], mod - 2, mod) % mod * pw(fact[n - m], mod - 2, mod) % mod;
	}
	int Ask_triangle(int x, int y) {
		return Triangle[x][y];
	}
}
using namespace OI;
using namespace COMB;

//#define fre 1
#define IOS 1
#define multitest 1

const int N = 2e5 + 10;
const int M = 4e5 + 10;
const int inf = 1e12;

string a, b;
int n;


il void Init() {
	cin >> n;
	cin >> a >> b;
}

il void Solve() {
	if (a == b) {
		cout << "Yes\n";
		return ;
	}
	int x = a.find("1");
	int y = b.find("1");
	if (x == -1 && y == -1) {
		cout << "Yes\n";
		return ;
	} else if (x == -1) {
		cout << "No\n";
		return ;
	} else {
		int cnt = 0;
		for (int i = 0; i < n; i ++ ) {
			if (a[i] == '1') cnt++;
			if (b[i] == '1' && !cnt) {
				cout << "No\n";
				return ;
			}
		}
		cout << "Yes\n";
	}
}
signed main() {
	int T;
#ifdef IOS
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
#ifdef fre
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
#ifdef multitest
	cin >> T;
#else
	T = 1;
#endif
	while (T--) {
		Init();
		Solve();
	}
	return 0;
}
/*

*/

标签:ch,return,int,题解,while,Game,Fun,mod,define
From: https://www.cnblogs.com/zla2012/p/18502065

相关文章

  • 题解:CF633D Fibonacci-ish
    涉及知识点:枚举,STL。题目大意给你一个序列,让你选出一些元素,使其构成fibonacccccci数列,求数列的最大长度。解题思路定义一个桶,$mp_i$代表$i$这个数在输入序列当中出现的次数。由于$n\le1000$,所以可以直接暴力枚举fibonacccccci数列的前两个数。前两个数固定了,这......
  • vue 项目history模式刷新404问题解决办法
    前言vue项目history模式部署到服务器后,根路径访问没有问题,但是进入其他功能再刷新页面就会出现404,因为你没在nginx或者apache配置上面加上重定向跳转。解决办法,只需要加上这段配置:nginx配置内容:location/{try_files$uri$uri/@router;indexindex.html;}lo......
  • 蓝桥杯大赛 ——首场算法团队战题解
    1. 不同角度【算法赛】在生活中,我们总是根据数值的大小来判断两个数字的大小关系。例如,9999 总是小于 100100,999999 总是小于 10001000。但如果我们换一个角度,将 999999 和 10001000 看成是两个数字字符串,并用字典序来比较它们的大小,那么此时,999999 将大于 10001000。......
  • [题解]P4552 [Poetize6] IncDec Sequence
    P4552[Poetize6]IncDecSequence我们对\(a\)做差分,得到数组\(b\)。\(a\)的区间修改,等价于选定\(i,j\in[1,n+1]\),令\(b[i]\leftarrow(b[i]+1),b[j]\leftarrow(b[j]-1)\),我们的目标是让\(b[2\simn]\)全为\(0\)。记\(x,y\)分别表示\(b[2\simn]\)中正数之和、负数的绝对值之和......
  • [Coci2011]kamion 题解
    前言题目链接:Hydro&bzoj;黑暗爆炸。题意简述给你一张\(n\)个点\(m\)条边的有向图。有\(p\)种括号,每条边的边权可以是这\(p\)种括号中某一种的左括号或者右括号,也可以为空。问你有多少条从\(1\)开始到\(n\)的长度小于等于\(k\)的路径,满足括号匹配,或者剩余若干未......
  • 题解:P3012 [USACO11FEB] Cowlphabet G
    [USACO11FEB]CowlphabetG题意有\(P\)种拼接方式,问由\(U\)个大写字母和\(L\)个小写字母合法组合的方案数。输出方案数对\(97654321\)取模的值。思路动态规划,还没有人写逆推方法,刚好我做的逆推。设\(f[i][j][z]\)表示一共有\(i\)个字母,其中\(j\)个为小写字母,......
  • 题解:CF2030C A TRUE Battle
    LuoguLink|CodeforcesLink\(\texttt{Describe}\)给一个长度为\(n\)的二进制序列,Alice和Bob在相邻两个0/1中间分别加\(\operatorname{or}\)或\(\operatorname{and}\)操作,优先级满足\(\operatorname{and}>\operatorname{or}\)。Alice希望最后运算的值为\(1\),Bo......
  • P8164 [JOI 2022 Final] 沙堡 2 题解
    DescriptionJOI君在沙滩上堆沙堡,他已经做好了一个沙堡,沙堡可以使用一个\(H\timesW\)的二维矩形表示,其被划分成若干个\(1\times1\)的小格子,格子高度互相不同。JOI君决定在沙堡上游走,他可以从任意一个点出发,向上下左右四个方向行走,必须满足他行走的路径单调下降。出于一......
  • 题解:Maximum AND
    ProblemLinkMaximumAND题外话用sort肘过去了?题面翻译给定数组\(a\)和\(b\),重排\(b\)数组,求\(a_i\oplusb_i\)之后与和的最大值。Solution不难想到按位贪心。从最高位开始,逐位讨论是否能为\(1\)。接下来有一个做法:先将\(a\)数组升序排序,\(b\)数组降序排......
  • 【Azure Function】Python Function部署到Azure后报错No module named '_cffi_backend
    问题描述本地使用Python编写的FunctionApp,发布到AzureFunction后,出现 _cffi_backendmodule无法找到的报错。ERROR:Error:Nomodulenamed'_cffi_backend',Cannotfindmodule.Pleasechecktherequirements.txtfileforthemissingmodule.Formoreinfo,plea......