ACM Color the fence
Color the fence
- 描述
-
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的更多相关文章
- 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 ...
- [ACM] POJ 3253 Fence Repair (Huffman树思想,优先队列)
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25274 Accepted: 8131 Des ...
- B. Color the Fence
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
随机推荐
- 【JAVA使用XPath、DOM4J解析XML文件,实现对XML文件的CRUD操作】
一.简介 1.使用XPath可以快速精确定位指定的节点,以实现对XML文件的CRUD操作. 2.去网上下载一个“XPath帮助文档”,以便于查看语法等详细信息,最好是那种有很多实例的那种. 3.学习X ...
- AngularJS 之 Factory、Service、Provider
当你初试 Angular 时,很自然地就会往 controller 和 scope 里堆满不必要的逻辑.一定要早点意识到,controller 这一层应该很薄:也就是说,应用里大部分的业务逻辑和持久化 ...
- 攻城狮在路上(叁)Linux(十一)--- 用户与用户组、文件权限、目录配置
一.用户与用户组: 3个概念:文件所有者(user).用户组(group).其他人(others). /etc/passwd <==存放所有的用户名 /etc/shadow <==存放 ...
- 【leetcode】Candy
题目描述: There are N children standing in a line. Each child is assigned a rating value. You are giving ...
- [JAVA] IOException: Invalid byte 2 of 2-byte UTF-8 sequence(解决办法)
日志打印不全,后台只打印出出标题的异常信息: 先前的日志打印信息:log.debug(e.getMessage()); 后面改成了日志打印信息:log.debug(e); log.debug(e.ge ...
- C++ 简单的学生信息管理系统
// // main.cpp // 2013-7-17作业1 // // Created by 丁小未 on 13-7-17. // Copyright (c) 2013年 dingxiaowei. ...
- 用C#基于WCF创建TCP的Service供Client端调用
本文将详细讲解用C#基于WCF创建TCP的Service供Client端调用的详细过程 1):首先创建一个Windows Service的工程 2):生成的代码工程结构如下所示 3):我们将Servi ...
- Java生成验证码小工具
无意中看到一个生成简易验证码的小工具类(保存学习): 工具类代码: import java.awt.BasicStroke; import java.awt.Color; import java.aw ...
- Something about "for"
For语句引导了一个循环语句,格式for(::),例for(int i=0;i<100;i++).类似于if()括号的作用for()括号如同if()括号一样也是一个boolean型.int i= ...
- [自动运维]weblogic自动发布
近期一个项目属于测试过渡期,bug修复比较频繁,每次都会伴随着项目的打包.上传.发布,此类重复操作近乎每天都会进行,刚好最近在看python相关资料,决定重新将此前学习的weblogic的wlst相关 ...