跳到正文

题解

题解:B4350 [信息与未来 2025] 美味水果

Charged_Charge约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月14日
篇幅
约 1 分钟
题目
B4350

版本

  1. v1当前

洛谷 B4350

题目大意:

有 nn 个水果,每个水果的美味值为 aia_i,每天,每个水果的美味值变成 ai\sqrt{a_i}。求最多能获取多少美味值。

解题思路:

简单贪心。很明显,大的数开根后,缩减的美味值一定大于小的数缩减的美味值。所以我们直接对原数组倒序排列,先吃美味值较大的水果。然后模拟对后面所有水果的美味值开根。注意:11 开根后还是 11,可以特判减少时间。

AC 代码:

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+20;
int n, ans;
int a[N];
bool cmp(int x, int y) {
	return x > y;
}

signed main() {
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	sort(a + 1, a + 1 + n, cmp);

	for (int i = 1; i <= n; i++) {
		if (a[i] == 1) {
			ans++;
			continue;
		}

		ans += a[i];

		for (int j = i + 1; j <= n; j++) {
			a[j] = sqrt(a[j]);
		}
	}

	cout << ans;
	return 0;
}
原文