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个数字,现 ...
随机推荐
- 汉澳sinox通过ndis执行windows驱动程序
汉澳sinox不仅能通过wine执行windows应用程序.还能通过ndis执行windows驱动程序 汉澳sinox使用 Windows NDIS 驱动程序 详细实现方法是用ndisgen把wind ...
- C语言枚举类型(Enum)
在实际编程中,有些数据的取值往往是有限的,只能是非常少量的整数,并且最好为每个值都取一个名字,以方便在后续代码中使用,比如一个星期只有七天,一年只有十二个月,一个班每周有六门课程等. 以每周七天为例, ...
- RecyclerView的万能切割线
效果图: 用法: 加入默认切割线:高度为2px.颜色为灰色 mRecyclerView.addItemDecoration(new RecycleViewDivider(mContext, Linea ...
- eclipse Kepler tomcat内存溢出解决方式
使用eclipse开发ssh项目,本机8G内存,可是在打开一个表格后再打开一个页面.立即就内存溢出,网上搜到下面解决方式,未解决: 1.改动eclipse.ini參数 -vmargs -Xms1024 ...
- FlashBuilder找不到所需要的AdobeFlashPlayer调试器版本的解决方案
这个问题就是因为你所装的FlashPlayer不是调试器版本.如果你的FlashPlayer是调试版,那么你随便打开一个有Flash的页面,然后右键点击Flash,就会有一个调试器,菜单,当然它现在是 ...
- java utf8字符 导出csv 文件的乱码问题。
在输出的格式为UTF-8的格式,但是打开CSV文件一直为乱码,后来参考了这里的代码,搞定了乱码问题,原文请参考:http://hbase.iteye.com/blog/1172200 private ...
- Java数据结构与算法之排序
排序从大体上来讲,做了两件事情: 1.比較两个数据项: 2.交换两个数据项.或复制当中一项 一.冒泡排序 大O表示法:交换次数和比較次数都为O(N*N). 算法原理: 1.比較相邻的元素.假设第一个比 ...
- ssh命令、ping命令、traceroute 命令所使用的协议
在Node reboot or eviction: How to check if yourprivate interconnect CRS can transmit network heartbea ...
- region split流程分析
region split流程分析 splitregion的发起主要通过client端调用regionserver.splitRegion或memstore.flsuh时检查并发起. Client通过r ...
- es 300G 数据删除 执行计划 curl REST 操作
es 300G 数据删除 [es union_2017执行计划] [测试执行环境]线上D服务器[测试用例]get:curl -XGET ES:9200/_cat/indices?v post:curl ...