AtCoder Beginner Contest 336

题目链接: AtCoder Beginner Contest 336

A - Long Loong

题意:输出Long,其中'o'的数量等于n

解题思路:签到(其实没看清楚题目wa了一发)

void solve(){
	int n;
	cin >> n;
	cout << 'L';
	while(n --) cout << 'o';
	cout << "ng";
}

 

B - CTZ

题意:求对应数字的二进制的末尾0

解题思路:反复%2即可

void solve(){
	ll a;
	cin >> a;
	int ans = 0;
	while(a % 2 == 0){
		ans ++;
		a /= 2;
	}
	cout << ans << '\n';
}

 

C - Even Digits

题意:定义好整数为每个数位都是偶数(0,2,4,6,8),求第n个好数

解题思路:进制转换,也就是转化为五进制,但是因为0是第一项,所以先减去1

string ten_to_p(int x, int p) {
	string res;
	int tmp = 0;
	do {
		tmp = x % p;
		if (tmp < 10) res.push_back('0' + tmp);
		else res.push_back('A' + tmp - 10);
		x /= p;
	} while(x);
	//res中从size()-1到0倒序存储
	return res;
}

void solve(){
	int n;
	cin >> n;
	n --;
	string s = ten_to_p(n, 5);
	
	reverse(s.begin(), s.end());
	for(auto i : s){
		if(i == '0') cout << 0;
		else if(i == '1') cout << 2;
		else if(i == '2') cout << 4;
		else if(i == '3') cout << 6;
		else if(i == '4')cout << 8;
	}
}

 

D - Pyramid

题意:给定一个数列,有两种操作:

1:将某一项-1

2:去掉头部或者尾部元素

定义金字塔序列为:1, 2, 3, 4,......,n - 1,n,n - 1,.....,4,3,2,1,求最长金字塔序列的中间值

解题思路:用递推的方式,分别计算每一项前面能够构造出的最长连续上升连续子序列长度q,以及每一项后面能够构造出的最长连续下降子序列长度p,最后的答案就算min(q[i],p[i])

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = n; i >= 1; i --) p[i] = min(p[i + 1] + 1, a[i]);
	for(int i = 1; i <= n; i ++) q[i] = min(q[i - 1] + 1, a[i]);
	int ans = 0;
	for(int i = 1; i <= n; i ++){
		ans = max(ans, min(q[i], p[i]));
	} 
	cout << ans << '\n';
}

 

posted @ 2024-01-17 21:01  Rosmontis_L  阅读(18)  评论(0编辑  收藏  举报