hdu 1248 寒冰王座 (水)

点击打开链接

题目意思:买东西,有三种价格的商品150 200 350,商店不找零,所以多余的钱给商店,求给商店的最少的钱

 

暴力求解!!

#include<stdio.h>
int main()
{
	int t,a,b,c,n,i,j,k,max,temp;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);max=0;
		a=n/150;b=n/200;c=n/350;
		for(i=0;i<=a;i++)
			for(j=0;j<=b;j++)
				for(k=0;k<=c;k++)
				{
					temp=150*i+200*j+350*k;
					if(temp>max&&temp<=n)
						max=temp;
				}
				printf("%d\n",n-max);
    }
	return 0;
}


posted on 2012-09-02 09:18  Slege  阅读(110)  评论(0编辑  收藏  举报

导航