等价串

https://www.nowcoder.com/acm/contest/134/F

题解:
可以发现顺序是无关的,也就是说001一定可以从100或者010转换而来。
又可以发现,1可以自增成1111(4个1)或者1111111(7个1),也就是说可以自增3n的长度,当然n属于R。
那么现在需要做的就是把A和B都转化成0或者1的串,然后判断他们长度之间的关系。


#include 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef vector vi;
typedef vector vii;
typedef vector vll;

const int MAXN = 1e6 + 10;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const double eps = 1e-8;

int n, m, k;
string str, ptr;

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << setprecision(10) << fixed;
	int times;
	cin >> times;
	while(times--){
		cin >> n >> m;
		cin >> str >> ptr;
		int res = 0;
		for(int i = 0; i < n; i++)
			res += 1 + str[i] - '0';
		for(int i = 0; i < m; i++)
			res -= 1 + ptr[i] - '0';
		if(res % 3)
			cout << "NO" << endl;
		else 
			cout << "YES" << endl;
	}
	cerr << "execute time : " << (double)clock() / CLOCKS_PER_SEC << endl;
	return 0;
}

你可能感兴趣的:(牛客,思维题型/数论相关)