1060 爱丁顿数 (25分)这是我遇到过的最简单的25分的题目,哈哈

#include <iostream>
#include<algorithm>
using namespace std;
int a[100001];
bool cmp(int a,int b) {
	if (a > b)
		return true;
	else
		return false;
}
int main()
{
	int n,i;
	bool flag=false;
	cin >> n;
	for ( i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n,cmp);
	for ( i = 0; i < n; i++) {
		if (a[i] <= i + 1) 
			break;
	}
	cout << i ;
}

用sort函数降序排列,比如10,9,8,8,7,7,6,6。10对应1天超过1英里,9对应2天超过两英里,以此类推,直到6的适合,6小于等于7,那么跳出for循环,这时i的值即为题目所求的值。

发布了17 篇原创文章 · 获赞 0 · 访问量 187

猜你喜欢

转载自blog.csdn.net/w17390956947/article/details/104945273