开始 2024-08-22 00:00:00

8.19-8.24集训第四天

结束 2024-08-26 09:00:00
Contest is over.
当前 2024-12-22 14:19:57

A题.AC题解
#include <iostream>//祖传开头
using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[n];
	for (int i = 0 ; i < n ; i ++)
		cin >> a[i];
	int ans = 0,sum = 0;
	for (int i = 0 ; i < n ; i ++)
		sum += a[i];
    int num = sum / n;
    for (int i = 0 ; i < n ; i ++)
		a[i] -= num;
    for (int i = 0 ; i < n - 1 ; i ++)
    {
		if (a[i] != 0)
		{
			ans ++;
			a[i + 1] += a[i];
		}
   }
   cout<<ans<<endl;
   return 0;
}

思路:贪心


HAPPY1  •  4个月前

比赛已结束。