CodeForces Codeforces Round #547 (Div. 3) 2019年3月20日 (补题)
A.

Examples
Input
120 51840
Output
7
Input
42 42
Output
0
Input
48 72
Output
-1
#include <iostream>
using namespace std;
int main()
{
	int m, n;
	cin >> m >> n;
	int step = 0;
	if (n % m != 0)
	{
		cout << -1 << endl;
		return 0;
	}
	else
	{
		int k = n / m;
		while (k % 2 == 0) {
			k /= 2;
			step++;
		}
		while (k % 3 == 0) {
			k /= 3;
			step++;
		}
		if (k != 1) {
			cout << -1 << endl;
		}
			
		else
		{
			cout << step << endl;
		}
	}
}
B.

Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
 3
Input
3
0 0 0
Output
 0
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a[200001];
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int s = 0;
	int max1 = 0;
	if (a[0] == 0) {
		
		for (int i = 1; i < n; i++) {
			if (a[i] == 1) {		
				++s;
				max1 = max(s, max1);
				continue;
			}
			max1 = max(s, max1);
			s = 0;
		}
		cout << max1 << endl;
	}
	if (a[0] == 1) {
		if (a[n - 1] == 0) {
			for (int i = 0; i < n; i++) {
				if (a[i] == 1) {
					++s;
					max1 = max(s, max1);
					continue;
				}
				max1 = max(s, max1);
				s = 0;
			}
			cout << max1 << endl;
		}
		else {
			int aa = 0;
			for (int i = n - 1; a[i] == 1 && i >= 0; i--) {
				s++;
				aa = i;
			}
			for (int i = 0; i < aa; i++) {
				if (a[i] == 1) {
					++s;
					max1 = max(s, max1);
					continue;
				}
				max1 = max(s, max1);
				s = 0;
			}
			cout << max1 << endl;
		}
	}
}
 
    作者:LightAc  
出处:https://www.cnblogs.com/lightac/  
联系:
Email: dzz@stu.ouc.edu.cn  
QQ: 1171613053
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。 

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号