跳到正文

个人记录

5-8总结

落落的去约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前

标题

第一题

错误代码

C++
/*
*/
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int N = 2e5 + 10;

int main()
{

	return 0;
}

正确代码

C++
/*
思路
/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int N = 2e5 + 10;
int a[200005], n, r=0;//r:最右边球的位置
int main(){
	cin >> n;
	while(n--){ //n次操作
		int x; cin>>x;
		a[++r] = x; // 1左移x位相当于 2^x
		if(r<=1) continue;
		else if(a[r]!=a[r-1]) continue;
		else if(a[r]==a[r-1]){
			while(r>=2 && a[r]==a[r-1]){
				int t = a[r] + 1;
				a[r-1] = t;
				r--;
			}
		}
	}
	cout << r;
	return 0;
}
原文