只有Subtask#1新增的测试点错了,已特判0,已写注释,谢谢大佬!
查看原帖
只有Subtask#1新增的测试点错了,已特判0,已写注释,谢谢大佬!
1159838
Dream_2522181190楼主2024/9/13 20:34
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int>s;
long long sum = 0;
signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;cin >> n;
	int MIN = INT_MAX;
	for (int i = 0; i < n; i++)
	{
		int k; cin >> k;
		s.push_back(k);
	}
	sort(s.begin(), s.end());//排序

	int MAX = *(s.end() - 1);//序列中最大的数
	for (int i = 0; i < n - 1; i++)
		MIN = min(MIN, s[i + 1] - s[i]);//找出序列中最小的公差

	if (MIN == 0)//特判0
	{
		cout << n;return 0;
	}
	int shuzi = *s.begin();//序列中最小的数字
	while (1)
	{
		shuzi += MIN;//从最小的数字开始,持续加上公差
		sum++;//记录有多少元素
		if (shuzi > MAX)//当大于最大数的时候,跳出循环
			break;
	}
	cout << sum;
	return 0;
}
2024/9/13 20:34
加载中...