Color the fence
2015-07-28 20:19
316 查看
Color the fence
时间限制:1000 ms | 内存限制:65535 KB难度:2
描述
Tom has fallen in love with Mary. Now Tom wants to show his love and write a number on the fence opposite to
Mary’s house. Tom thinks that the larger the numbers is, the more chance to win Mary’s heart he has.
Unfortunately, Tom could only get V liters paint. He did the math and concluded that digit i requires ai liters paint.
Besides,Tom heard that Mary doesn’t like zero.That’s why Tom won’t use them in his number.
Help Tom find the maximum number he can write on the fence.
输入There are multiple test cases.
Each case the first line contains a nonnegative integer V(0≤V≤10^6).
The second line contains nine positive integers a1,a2,……,a9(1≤ai≤10^5).输出Printf the maximum number Tom can write on the fence. If he has too little paint for any digit, print -1.样例输入
55 4 3 2 1 2 3 4 529 11 1 12 5 8 9 10 6
样例输出
5555533
源代码如下:
#include<stdio.h>
int main()
{
int i,j,v,a[10];
while(scanf("%d",&v)!=EOF)
{
int t=0;
for(i=1;i<=9;i++)
{
scanf("%d",&a[i]);
}
int min=a[1];
for(i=1;i<=9;i++)
{
if(min>=a[i])
{
min=a[i];
}
}
for(i=v/min;i>=1;i--)//计算最多能刷几个数字(包含相同的数字或者不同的数字)
{
for(j=9;j>=0;j--)
{
if(v>=a[j]&&(v-a[j])/min>=i-1)//判断j数字能否被刷,且剩余的涂料可以刷剩下的i-1个数字
{
printf("%d",j);
v-=a[j];
break;
}
}
}
printf("\n");
}
return 0;
}
相关文章推荐
- 每天一个小知识点16(Angularjs总结四)
- Bootstrap 模态框(Modal)插件
- 移动开发中 HTML5 能否替代本地程序?
- HTML CSS简单总结
- 强制html元素不随窗口缩小而换行
- h5学习之调用手机底层硬件----加速度传感器和震动
- struct inode 和 struct file
- Bootstrap css栅格 + 网页中插入代码+css表格
- 聊聊css盒子模型
- Javascript对象的创建模式 -- 深入了解Javascript
- SharedPreferences数据存储
- XHTML基础
- JavaScript DOM入门
- Json解析
- <Web> jsp:EL表达式+C标签
- CSS截取字符串,额外的文本显示以省略号
- LeetCode题解——Swap Nodes in Pairs
- PackageManager hasSystemFeature
- HDU 1203 I NEED A OFFER! 最大概率
- 高性能JavaScript 加载和执行