hdu2401 Baskets of Gold Coins

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2401


/*假设1--N-1个篮子里的金币一样重,weight=w*(1+n-1)*(n-1)/2
减去已知的重量W,(weight-W)/d得金币数量即篮子编号*/
#include <stdio.h>

int main()
{
	int n,w,d,W,ans;
	while(scanf("%d %d %d %d",&n,&w,&d,&W)!=EOF)
	{
		ans=(w*n*(n-1)/2-W)/d;
		if(ans>0)
			printf("%d\n",ans);
		else
			printf("%d\n",n);
	}
	return 0;
}


你可能感兴趣的:(hdu2401 Baskets of Gold Coins)