玄关,11#TLE
查看原帖
玄关,11#TLE
773371
Dreeick楼主2024/5/31 14:57

思路来源于这篇题解

代码如下

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n,a[100001];
vector<pair<int,int>> v;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i = 0;i < n;i++){
		bool is = true;
		for(int j = 0;j < v.size();j++){
			if(a[i] == v[j].second + 1){
				auto t = v[j];
				v.erase(v.begin()+j);
				t.first++;
				t.second++;
				v.insert(lower_bound(v.begin(),v.end(),t),t);
				is = false;
				break;
			}
		}
		if(is){
			v.insert(lower_bound(v.begin(),v.end(),make_pair(1,a[i])),make_pair(1,a[i]));
		}
	}
	cout << v[0].first;

	return 0;
}

第11个点T了

我感觉是这一段出了问题,但是不知道怎么改

for(int j = 0;j < v.size();j++){
			if(a[i] == v[j].second + 1){
				auto t = v[j];
				v.erase(v.begin()+j);
				t.first++;
				t.second++;
				v.insert(lower_bound(v.begin(),v.end(),t),t);
				is = false;
				break;
			}
		}

万望DALAO提出修改意见,将感激不尽!

2024/5/31 14:57
加载中...