南阳oj 791 Color the fence
来源:互联网 发布:股票资产分析软件 编辑:程序博客网 时间:2024/05/02 00:59
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.
样例输入
5
5 4 3 2 1 2 3 4 5
2
9 11 1 12 5 8 9 10 6
样例输出
55555
33
#include<stdio.h>#include<cstring>#include<iostream>#include<algorithm>#include<math.h>#include<stdlib.h>#include<stack>#include<vector>#include<string.h>#include<map>#define INF 0x3f3f3f3f3fusing namespace std;int main(){ int v; while(~scanf("%d",&v)) { int a[10]; int min=100005; int t=0; for(int i=1; i<=9; i++) { scanf("%d",&a[i]); if(min>a[i]&&i>t) { min=a[i]; t=i; } } if(min>v) { printf("-1\n"); continue; } int wei=v/min; //printf("wei=%d\n",wei); for(int i=wei-1; i>=0; i--) { for(int j=9; j>=1; j--) { if(v>=a[j]&&(v-a[j])/min>=i) { v-=a[j]; printf("%d",j); break; } } } printf("\n"); }}
- 南阳oj(nyoj) 791 Color the fence
- 南阳oj 791 Color the fence
- 南阳791 Color the fence
- 791 Color the fence
- Color the fence(南阳oj791)(贪心+策略)
- NYOJ-791 Color the fence
- NYOJ 791 Color the fence
- nyoj 791 Color the fence
- NYOJ 791 Color the fence
- nyoj 791 Color the fence
- nyoj 791 Color the fence 【贪心】
- nyoj 791 Color the fence(贪心)
- NYOJ-791 Color the fence (来源CodeForce)
- acm-Color the fence
- nyoj color the fence
- Color the fence
- Color the fence
- Color the fence
- pip网络超时解决办法
- Gdal库读取和生成图像数据
- TCP四次握手断开连接
- Android建造者模式
- ES单播发现主节点配置如下:
- 南阳oj 791 Color the fence
- phpstorm 界面设置
- spring注入elasticsearch
- js控制table中tr位置互换
- Fedora25 桌面启动与grub管理
- 使用spark检查数据质量
- 零拷贝:
- 友元类
- RocketMQ和Trident