Description
Input consists of several test cases. Each test case consists of three integers m, n, t (0 < m,n,t < 10000). Input is terminated by EOF.<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPGgzPk91dHB1dDwvaDM+CjxwPkZvciBlYWNoIHRlc3QgY2FzZSwgcHJpbnQgaW4gYSBzaW5nbGUgbGluZSB0aGUgbWF4aW11bSBudW1iZXIgb2YgYnVyZ2VycyBIb21lciBjYW4gZWF0IHdpdGhvdXQgaGF2aW5nIGJlZXIuIElmIGhvbWVyIG11c3QgaGF2ZSBiZWVyLCB0aGVuIGFsc28gcHJpbnQgdGhlIHRpbWUgaGUgZ2V0cyBmb3IgZHJpbmtpbmcsIHNlcGFyYXRlZCBieSBhIHNpbmdsZSBzcGFjZS4KIEl0IGlzIHByZWZlcmFibGUgdGhhdCBIb21lciBkcmlua3MgYXMgbGl0dGxlIGJlZXIgYXMgcG9zc2libGUuPC9wPgo8aDM+U2FtcGxlIElucHV0PC9oMz4KPHByZSBjbGFzcz0="brush:java;">3 5 54 3 5 55
18 17
Problem setter: Sadrul Habib Chowdhury
Solution author: Monirul Hasan (Tomal)
Time goes, you say? Ah no!
Alas, Time stays, we go.
-- Austin Dobson
題目大意:
輸出不浪費時間時吃漢堡的最大數目,否則輸出漢堡在最小浪費時間情況下吃漢堡的最大數目和最小浪費時間。
解題思路:
貪心,對花費時間小的先分,然後逐漸減少此漢堡個數,增加另一個漢堡的個數。
#include#include using namespace std; int main(){ int m,n,t,x1,y1,temp; while(scanf("%d%d%d",&m,&n,&t)!=EOF){ int flag=0,mint=10000; if(m>n){ temp=m;m=n;n=temp; } int x=t/m,y=0; for(;x>=0;){ if(t==m*x+n*y){ printf("%d\n",x+y);flag=1;break; } else if((t-m*x-n*y)%n!=0&&(t-m*x-n*y)/n==0){ if(t-m*x-n*y