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. 注意kvm在安装虚机的时候不能把存放虚机的文件放在/root 下面

    如果放在/root下面会报错: WARNING KVM acceleration not available, using 'qemu' Starting install... Creating st ...

  2. Jquery学习笔记---闭包

    1. 简要介绍 闭包可谓是js中的一大特色了,即使你对闭包没概念,你可能已经在不知不觉中使用到了闭包.闭包是什么,闭包就是一个函数可以访问到另一个函数的变量.这就是闭包,解释起来就这么一句话,不明白? ...

  3. jQuery积累

    一:Google的CDN(内容分发网络) <head> <script type="text/javascript" src="http://ajax. ...

  4. HTML5学习之WebSocket通讯(六)

    WebSocket是下一代客户端-服务器的异步通信方法. WebSocket最伟大之处在于服务器和客户端可以在任意时刻相互推送信息 WebSocket允许跨域通信 Ajax技术需要客户端发起请求,We ...

  5. Sexagenary Cycle(天干地支法表示农历年份)

    Sexagenary Cycle Time Limit: 2 Seconds      Memory Limit: 65536 KB 题目链接:zoj 4669 The Chinese sexagen ...

  6. poj 1724:ROADS(DFS + 剪枝)

    ROADS Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10777   Accepted: 3961 Descriptio ...

  7. 无法打开包括文件:“windows.h”: No such file or directory

      VS2012 出现如下错误: 无法打开包括文件:"windows.h": No such file or directory   解决办法,将 C:\Program Files ...

  8. PAT A 1014. Waiting in Line (30)【队列模拟】

    题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...

  9. java-xml格式化

    参考:http://www.oschina.net/code/snippet_17793_4733 package com.ddatsh;   import java.io.IOException; ...

  10. 如果我可以重新学习iOS开发(转)

    在过去的几个月里,我一直在学习用Objective-C编写iOS app,最后我开始理清思绪.这比我想象中要难很多,也花了太长时间. 我经常遇到困难.感到沮丧,修复bug比实际写代码要花太多时间.但是 ...