B. Color the Fence
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digit d requires ad liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number.
Help Igor find the maximum number he can write on the fence.
InputThe first line contains a positive integer v (0 ≤ v ≤ 106). The second line contains nine positive integers a1, a2, ..., a9 (1 ≤ ai ≤ 105).
OutputPrint the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.
Examplesinput5
5 4 3 2 1 2 3 4 5output55555input2
9 11 1 12 5 8 9 10 6output33input0
1 1 1 1 1 1 1 1 1output-1
被这道题卡了蛮久,只考虑到了位数最大,没想到要尽可能小以给高位腾出更多空间。
附AC代码:
#include<bits/stdc++.h>
using namespace std; int a[]; const int INF=<<; int main(){
int v,temp=;
int Max=;
int Min=INF;
cin>>v;
for(int i=;i<=;i++){
cin>>a[i];
if(v/a[i]>Max||a[temp]==a[i]){
Max=v/a[i];
temp=i;
}
if(a[i]<=Min){
Min=a[i];
}
}
if(Max==){
cout<<-<<endl;
return ;
}
else{
int num=v/a[temp]; Min=INF;
for(int i=temp+;i<=;i++){
if(a[i]<=Min){
Min=a[i];
}
}
v%=a[temp];
while(v>&&v+a[temp]>=Min){
int t;
for(int i=;i>temp;i--){
if(a[i]<=v+a[temp]){
cout<<i;
num--;
t=i;
break;
}
}
v-=abs(a[t]-a[temp]);
}
for(int i=;i<num;i++){
cout<<temp;
} cout<<endl;
}
return ;
}
B. Color the Fence的更多相关文章
- ACM Color the fence
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- NYOJ-791 Color the fence (贪心)
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- 349B - Color the Fence
Color the Fence Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Su ...
- nyoj Color the fence
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- Codeforces 349B - Color the Fence
349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...
- nyoj 791——Color the fence——————【贪心】
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- Codeforces D. Color the Fence(贪心)
题目描述: D. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- codeforces B. Color the Fence 解题报告
题目链接:http://codeforces.com/problemset/problem/349/B 题目意思:给定v升的颜料和9个需要花费ad 升的颜料,花费ad 升的颜料意味着得到第d个数字,现 ...
随机推荐
- BUPT复试专题—中序遍历序列(2013)
题目描述 给出一个序列,判断该序列是不是某二叉搜索树的中序遍历序列,如果是输出"Yes",否则输出"No".一颗带权二叉树是一颗二叉搜索树(二叉排序树),当且仅 ...
- UVA 1482 - Playing With Stones(SG打表规律)
UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函 ...
- [Servlet&JSP] 标准标签
在JSP的规范中提供了一些标准标签(Standard Tag),全部的容器都支持这些标签,它能够协助编写JSP时降低Scriptlet的使用. 全部的标准标签都使用jsp:作为前置.这些标准标签是在J ...
- jQuery的ajax,当async为false时,同步操作失败。解决方式
引发失败时代码: $.ajax({ url : 'your url', data:{name:value}, cache : false, async : true, type : "POS ...
- [LeedCode OJ]#28 Implement strStr()
[ 声明:版权全部,转载请标明出处,请勿用于商业用途. 联系信箱:libin493073668@sina.com] 题目链接:https://leetcode.com/problems/implem ...
- 使用string实现一个用于储存那些太大而无法使用 long long 的数
类的定义: class stringInt { public: stringInt(); stringInt(string num); stringInt(int num); stringInt op ...
- Comparable 和 Comparator的理解
对Comparable 的解释 Comparable是一个排序接口 此接口给实现类提供了一个排序的方法,此接口有且只有一个方法 public int compareTo(T o); compareTo ...
- (转)gcc学习笔记
1.gcc -Wall hello.c -o hello //编译源文件,显示警告信息 2../a.out //运行程序 3.gcc -Wall calc.c /usr/lib/libm.a -o ...
- 文本分析实例---QQ聊天记录分析
对QQ聊天记录进行分析,由于每天产生的聊天记录比較多,所以选取的是从2月份整月的聊天记录数据.分析要产生的结果有三个,聊天记录中发消息的人前top15.统计24小时时间段那个时间段发贴人最多,还有对消 ...
- 利用ctypes调用Fortran程序
本来python下面调用fortran最傻瓜方便的办法就是f2py,但是若fortran和C混合编程的代码,分别指定gfortran和gcc为编译器,在windows下面f2py直接报错 那么ctyp ...