Color the Fence
Codeforces Round #202 (Div. 2) B:http://codeforces.com/problemset/problem/349/B
题意:给你一些颜料,然后你可以用这些颜料画一些数字,画每个数字的颜料是不一样的,然后问你用这些颜料可以画出的最大的数。
题解:和容易想到,直接用贪心,数字最大,首先要使得数字的位数最多,所以要选择需要颜料最少的数字来话,此题有一个好处就是,就是不用考虑前导零的情况,数的位数确定之后,就可以用剩余的颜料来调整数字,从高位到低位,每一次把把尽可能大的数字放在高位。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[],v;
int minn,pos,ct;
int ans[],top;
int main(){
while(~scanf("%d",&v)){
minn=1e7;
for(int i=;i<=;i++){
scanf("%d",&a[i]);
if(minn>=a[i]){
minn=a[i];
pos=i;
}
}
if(v<minn){
printf("-1\n");continue;
}
ct=v/minn;
int temp=v-ct*minn;
for(int i=;i<=ct;i++)
ans[i]=pos;
top=;
// printf("%d %d %d\n",ct,temp,minn);
while(temp>){
int tp=;
top++;
if(top>ct)break;
for(int i=;i<=;i++){
if(a[i]-minn<=temp)
tp=i;
}
if(tp==)break;
else {
ans[top]=tp;
temp-=(a[tp]-minn);
}
}
for(int i=;i<ct;i++){
printf("%d",ans[i]);
}
printf("%d\n",ans[ct]);
}
}
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 ...
- B. Color the Fence
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- codeforces B. Color the Fence 解题报告
题目链接:http://codeforces.com/problemset/problem/349/B 题目意思:给定v升的颜料和9个需要花费ad 升的颜料,花费ad 升的颜料意味着得到第d个数字,现 ...
随机推荐
- Access中出现改变字段“自己主动编号”类型,不能再改回来!(已解决)
Access中出现改变字段"自己主动编号"类型,不能再改回来! (已解决) 一次把access中的自增字段改成了数值,再改回自增时,提示:在表中输入了数据之后,则不能将不论什么字段 ...
- 关于怎么将Quartus和Nios程序一起固化到FPGA里面
系统:win8.1 SDK:Quartus II 14.1 FPGA:Cyclone IV 1.将Quartus生成的.pof文件(配置Flash即可自动生成,这里不讨论),与Nios生成的.elf文 ...
- java解析xml文件四种方式
1.介绍 1)DOM(JAXP Crimson解析器) DOM是用与平台和语言无关的方式表示XML文档的官方W3C标准.DOM是以层次结构组织的节点或信息片断的集合.这个层次结构允许开发人员在树中寻找 ...
- 一次优化web项目的经历记录(三)
一次优化web项目的经历记录 这段时间以来的总结与反思 前言:最近很长一段时间没有更新博客了,忙于一堆子项目的开发,严重拖慢了学习与思考的进程. 开水倒满了需要提早放下杯子,晚了就会烫手,这段时间以来 ...
- Codeforces 231E - Cactus
231E - Cactus 给一个10^5个点的无向图,每个点最多属于一个环,规定两点之间的简单路:从起点到终点,经过的边不重复 给10^5个询问,每个询问两个点,问这两个点之间有多少条简单路. 挺综 ...
- 实用脚本 - - addLoadEvent 页面加载完毕执行函数
function addLoadEvent(func){ var oldonload = window.onload; if(typeof window.onload != "functio ...
- [转帖]vivado & VS2013工具
来源:http://bbs.csdn.net/topics/380057699 添加OpenCV库后,MFC在Debug模式下调试,提示应用程序无法正常启动(0xc000007b). 解决方法:在环境 ...
- 使用AutoMapper实现Dto和Model之间自由转换
应用场景:一个Web应用通过前端收集用户的输入成为Dto,然后将Dto转换成领域模型并持久化到数据库中.另一方面,当用户请求数据时,我们又需要做相反的工作:将从数据库中查询出来的领域模型以相反的方式转 ...
- linux常用命令之tail
从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新,使你看到最新的 ...
- 用java写bp神经网络(四)
接上篇. 在(一)和(二)中,程序的体系是Net,Propagation,Trainer,Learner,DataProvider.这篇重构这个体系. Net 首先是Net,在上篇重新定义了激活函数和 ...