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个数字,现 ...
随机推荐
- 使用SourceTree 来管理 Gitcafe 的Pages 发布Blog!
有个好爹的 SourceTree 是来自 JIRA 的娘家 Bitbucket 的新东家 ATLASSIAN.com 一家成功的,对敏捷软件工程拥有全栈式支持的商业公司, 所推出的 MAC 专用, S ...
- how to avoid over-fitting?(机器学习中防止过拟合的方法,重要)
methods to avoid overfitting: Cross-Validation : Cross Validation in its simplest form is a one roun ...
- python之入门,你好,中国
print("你好,中国") 可以运行py文件实现一样的效果(py文件编码一定要是utf-8编码) 你好中国基础教程结束!
- 一致性hash算法在memcached中的使用
一.概述 1.我们的memcacheclient(这里我看的spymemcache的源代码).使用了一致性hash算法ketama进行数据存储节点的选择.与常规的hash算法思路不同.仅仅是对我们要存 ...
- react 创建组件 (二)component
因为ES6对类和继承有语法级别的支持,所以用ES6创建组件的方式更加优雅,下面是示例: import React from 'react'; class Greeting extends React. ...
- C#语言 函数
- html使用代码大全
<DIV style="FONT-SIZE: 9pt">1)贴图:<img src="图片地址">1)首行缩进2格:<p styl ...
- 在VC中动态加载ODBC的方法
在使用VC.VB.Delphi等高级语言编写数据库应用程序时,往往需要用户自己在控制面板中配置ODBC数据源.对于一般用户而言,配置ODBC数据源可能是一件比较困难的工作.而且,在实际应用中,用户往往 ...
- android自己定义开关控件
近日在android项目要使用开关控件.可是android中自带的开关控件不太惬意,所以就打算通过自己定义View写一个开关控件 ios的开关控件当然就是我要仿照的目标. 先上图: waterma ...
- 6.游戏特别离不开脚本(3)-JS脚本操作java(3)(直接操作JS文件或者调用函数)
java直接运行JS脚本文件的语句,游戏开发时,策划的配置文件什么的就可以分开管理了,游戏逻辑也是一样,比如:一个功能一个脚本或者一个系统一个脚本. import java.io.FileNotFou ...