349B - Color the Fence
Description
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.
Input
The first line contains a positive integer v(0 ≤ v ≤ 106). The second line contains nine positive integers a1, a2, ..., a9(1 ≤ ai ≤ 105).
Output
Print 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.
Sample Input
5
5 4 3 2 1 2 3 4 5
55555
2
9 11 1 12 5 8 9 10 6
33
0
1 1 1 1 1 1 1 1 1
-1
/*
题意:给你v升染料,有1-9个数字,写每个数字都耗费不同的燃料,问你用这些燃料最多能写出来的数字是多少 #感悟:爆炸,尽然没想起来这么贪,最长的长度肯定cur=v/minv然后,枚举cur位,都尽可能的取一个最大的数 */ #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int a[];
vector<int> v;
int n;
int minv=INF;
int mini;
int cur;
int main(){
// freopen("in.txt","r",stdin);
v.clear();
scanf("%d",&n);
for(int i=;i<;i++){
scanf("%d",&a[i]);
if(a[i]<=minv){
minv=a[i];
mini=i;
}
}
cur=n/minv;
if(cur==){
puts("-1");
return ;
}
int res=;
for(int i=;i<cur;i++){//查找每一位
for(int j=;j>=;j--){
//每一位都找最大的
if(n<=minv){
v.push_back(mini+);
break;
}
if(a[j]>n) continue;
if( (n-a[j])/minv+v.size()+==cur){
res+=a[j];
v.push_back(j+);
n-=a[j];
break;
}
}
}
for(int i=;i<v.size();i++){
printf("%d",v[i]);
}
printf("\n");
return ;
}
349B - Color the Fence的更多相关文章
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- Codeforces 349B - Color the Fence
349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...
- 【贪心】Codeforces 349B.Color the Fence题解
题目链接:http://codeforces.com/problemset/problem/349/B 题目大意 小明要从9个数字(1,2,--,9)去除一些数字拼接成一个数字,是的这个数字最大. 但 ...
- CodeForces 349B Color the Fence (DP)
题意:给出1~9数字对应的费用以及一定的费用,让你输出所选的数字所能组合出的最大的数值. 析:DP,和01背包差不多的,dp[i] 表示费用最大为 i 时,最多多少位,然后再用两个数组,一个记录路径, ...
- ACM Color the fence
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- NYOJ-791 Color the fence (贪心)
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- nyoj Color the fence
Color the fence 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Tom has fallen in love with Mary. Now Tom w ...
- 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 ...
随机推荐
- Scanner(键盘录入)
注意事件: 1: 当使用Scanner类时 切记不要做从键盘输入一个int数 再输入一个字符串 这样会导致bug就是字符串会读取不到几所输入的内容 原因是因为:当你用了NextInt()方法时,再按了 ...
- Ubuntu17.04安装wps
1.进入http://community.wps.cn/download/下载wps-office安装包,我下载的是dep的包. 2.进行安装执行命令:sudo dpkg -i wps-office_ ...
- Python基础知识总结
看了一个礼拜Python的书,断断续续的看了一大半.今天刚好没有课,想着也没什么事情干,就把这几天Python总结一下,都是一些基础知识 变量和对象的引用 在python中一切都是对象,不像C,jav ...
- java集合系列——Set之HashSet和TreeSet介绍(十)
一.Set的简介 Set是一个不包含重复元素的 collection.更确切地讲,set 不包含满足 e1.equals(e2) 的元素.对 e1 和 e2,并且最多包含一个为 null 的元素. S ...
- 每周分享一 之 webSocket
一:什么是webSocket ? webSocket是HTML5出的新协议,WebSocket协议支持,在受控环境中运行不受信任代码的客户端与选择了该代码通信的远程主机之间进行双向通信. 简单翻译一下 ...
- 石子合并(NOI1995)
石子合并(NOI1995) 时间限制: 1 Sec 内存限制: 128 MB提交: 90 解决: 48[提交][状态][讨论版] 题目描述 在操场上沿一直线排列着 n堆石子.现要将石子有次序地合并 ...
- UrlRewriter配置IIS支持伪静态
使用UrlRewriter时遇到了一些问题,在园子里的博问中找到了Astar的回答,防止以后找不到,就记录下来了. UrlRewriter.NET官方地址:http://urlrewriter.net ...
- css3弹性盒模型flex快速入门与上手1
一.什么是flex? flex是css3中引入的一种布局方式,可以非常灵活高效控制元素的排列与对齐方式,大多人称之为弹性布局. 二.怎么使用flex? 任何一个容器都可以指定为flex布局 #box ...
- VNC实现Windows远程访问Ubuntu 16.04(无需安装第三方桌面)
本文主要是讲解如果理由VNC实现Windows远程访问Ubuntu 16.04,其实网上有很多类似教程,但是很多需要安装第三方桌面(xfce桌面等等),而且很多人不太喜欢安装第三方桌面,很多人像笔者一 ...
- webpack2使用ch7-loader解析css 自动添加浏览器前缀
1 目录结构 安装的依赖 "autoprefixer": "^6.7.7", "css-loader": "^0.28.0&qu ...