View Code of Problem 1085

/*假设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;
}

Double click to view unformatted code.


Back to problem 1085