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
本题题意是给V升的油漆,以及1-9每个数字需要的油漆,问用这些油漆能刷出的最大的数字?
如给得第一个测试用例,有5升油漆,数字5需要1升油漆,故把数字5刷5次得到的数字最大
但存在这样的测试用例
9
5 4 2 3 5 4 6 4 5
则全用来刷数字3的话,为3333,还剩1升油漆
如果刷3个数字2,还剩3升用来刷数字4,则结果为4333,比全用来刷数字2大
同时还存在一种测试用例
8
5 4 3 2 5 4 6 1 1
有油漆相同的情况,应该选择数字最大的
本题还未考虑下面这种情况,参考codeforce给出的测试用例才知道
898207
99745 99746 99748 99752 99760 99776 99808 99872 100000
结果为987654321
#include <iostream>
#include <vector>
#include <algorithm> using namespace std; int main(){
int v;
while(cin >> v){
vector<int> num(,);
int minIndex = ;
for(int i = ; i < ; ++ i){
cin >> num[i];
if(num[minIndex]>=num[i]) minIndex = i;
}
if(v < num[minIndex]) cout<<-<<endl;
else if(v%num[minIndex] == ) cout<<string(v/num[minIndex],''+minIndex)<<endl;
else{
int cnt = v/num[minIndex], remain = v%num[minIndex];
for(int i = ; i < cnt; ++ i){
for(int j = ; j > ; -- j){
if(j <= minIndex){
cout<<minIndex;
break;
}
if(remain-(num[j]-num[minIndex]) >= ){
remain -=(num[j]-num[minIndex]);
cout<<j;
break;
}
}
}
cout<<endl;
}
}
}

 
 

ACM Color the fence的更多相关文章

  1. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  2. NYOJ-791 Color the fence (贪心)

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  3. 349B - Color the Fence

    Color the Fence Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

  4. nyoj Color the fence

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  5. Codeforces 349B - Color the Fence

    349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...

  6. nyoj 791——Color the fence——————【贪心】

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  7. Codeforces D. Color the Fence(贪心)

    题目描述: D. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. [ACM] POJ 3253 Fence Repair (Huffman树思想,优先队列)

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25274   Accepted: 8131 Des ...

  9. B. Color the Fence

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. C-线性顺序表的增删改查

    闲来无事,练练手,写点C代码,对于线性表的简单操作.编辑工具Notpad++,编译工具tcc. /* *the sequence of the list *author:JanneLee *data: ...

  2. 《Spring 3.x 企业应用开发实战》目录

    图书信息:陈雄华 林开雄 编著 ISBN 978-7-121-15213-9 概述: 第1章:对Spring框架进行宏观性的概述,力图使读者建立起对Spring整体性的认识. 第2章:通过一个简单的例 ...

  3. PHPCMS 多站点管理切换问题

    打开系统函数库global.func.php 可以看到获取站点ID的函数如下 /** * 获取当前的站点ID */ function get_siteid() { static $siteid; if ...

  4. base64编码、解码的C语言实现

    转自:http://www.cnblogs.com/yejianfei/archive/2013/04/06/3002838.html base64是一种基于64个可打印字符来表示二进制数据的表示方法 ...

  5. FAST特征点检测

    Features From Accelerated Segment Test 1. FAST算法原理 博客中已经介绍了很多图像特征检测算子,我们可以用LoG或者DoG检测图像中的Blobs(斑点检测) ...

  6. hdu 4784 Dinner Coming Soon(spfa + 优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4784 思路:建图,对于同一个universe来说,就按题目给的条件相连,对于相邻的universe,连 ...

  7. NSArray 所有基础点示例

    #import <Foundation/Foundation.h> //排序算法,应用于 NSArray *arr=[arrs1 sortedArrayUsingFunction:sort ...

  8. SQLServer 维护脚本分享(07)IO

    sp_helpfile --当前数据库文件分配情况 sp_spaceused --当前db空间大小(有时不准) sp_spaceused 'dbo.user' --指定表的空间大小(有时不准) sp_ ...

  9. 搭建ASP JSP运行环境

    搭建JSP 服务器 Java + HTML 的运行环境 服务端搭建ASP.NET运行环境

  10. 【gulp-sass】error: File to import not found or unreadable

    简要记录一下在使用gulp-sass时候踩的坑,虽然不明所以然,但是似乎在https://github.com/dlmanning/gulp-sass/issues/1 找到了答案. 在使用gulpf ...