diff --git a/POJ/3040_tuicool.cpp b/POJ/3040_tuicool.cpp new file mode 100644 index 0000000..2cc1eb2 --- /dev/null +++ b/POJ/3040_tuicool.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +const int INF=0x3f3f3f3f; +using namespace std; + +struct node +{ + int val,mou;//面值和数目 +} mon[25]; +int n,c; +int need[25];//一种方案所需各面值的数目 +bool cmp(node a,node b) +{ + return a.val=0;i--) + if(mon[i].val>=c)//如果面值大于c直接加数目就行了 + ans+=mon[i].mou; + else + { + lim=i; + break; + } + while(1) + { + memset(need,0,sizeof need); + rest=c; + for(i=lim;i>=0;i--)//尽可能用大面值凑够 + { + if(!mon[i].mou||!rest) + continue; + ti=rest/mon[i].val; + ti=min(ti,mon[i].mou); + need[i]=ti; + rest-=ti*mon[i].val; + } + if(rest)//没凑够的话。只能往回找最小的面值凑够。保证损失的钱最少 + { + for(i=0;i<=lim;i++) + { + if(mon[i].val>=rest&&(mon[i].mou-need[i])) + { + need[i]++; + rest=0; + break; + } + } + if(rest) + break; + } + mday=INF; + for(i=0;i<=lim;i++) + if(need[i]) + mday=min(mday,mon[i].mou/need[i]);//得出该种方案能支付的最大周数 + ans+=mday; + for(i=0;i<=lim;i++) + mon[i].mou-=mday*need[i]; + } + printf("%d\n",ans); + } + return 0; +} +/* +11 +6 1 +4 1 +*/