luogu P1031 均分纸牌

题目很简单,但是可以学一学贪心策略

把纸牌均匀分布,从左往右推掉不用的纸牌

#include <iostream>  
using namespace std;  
int main()  
{ 
	int a,p=0,js=0;
	cin>>a;
	int q[a];  
	for(int y=0;y<a;y++)
	{
		cin>>q[y];
		p+=q[y];
	}
	p/=a;  
	for (int y=0;y<a;y++)q[y]-=p;  
	for (int y=0;y<a;y++) 
	{
		if(q[y]==0)continue;
		q[y+1]+=q[y];
		js++; 
	}  
	cout<<js;  
	return 0;
}  
原文地址:https://www.cnblogs.com/naruto-mzx/p/11837806.html