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个数字,现 ...
随机推荐
- Qtcreator中经常使用快捷键总结
Qtcreator中经常使用快捷键总结 F1 查看帮助 F2 跳转到函数定义(和Ctrl+鼠标左键一样的效果) Shift+F2 声明和定义之间切换 F4 ...
- Qt 学习之路 :信号槽
信号槽是 Qt 框架引以为豪的机制之一.熟练使用和理解信号槽,能够设计出解耦的非常漂亮的程序,有利于增强我们的技术设计能力. 所谓信号槽,实际就是观察者模式.当某个事件发生之后,比如,按钮检测到自己被 ...
- 初步掌握Yarn的架构及原理
1.YARN 是什么? 从业界使用分布式系统的变化趋势和 hadoop 框架的长远发展来看,MapReduce的 JobTracker/TaskTracker 机制需要大规模的调整来修复它在可扩展性, ...
- ios中的界面跳转方式
ios中,两种界面跳转方式 1.NavgationController本身可以作为普通ViewController的容器,它有装Controller的栈,所以可以push和pop它们,实现你所说的跳转 ...
- Java——(五)Collection之List集合、ArrayList和Vector实现类
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- 一.List集合 List集合代表一个元素有序.客重复的集合,集合中每个元素都有其对应的顺序索引 ...
- iOS 数据持久化(1):属性列表与对象归档
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...
- C#开发学习——内联表达式
<%@ 表示:引用 <%# 表示:绑定 <%= 表示:取值 <%= 变量名%> Response.Write()输出和<%=%>输出最后的效果是一样的 ...
- <input value="hidden">的作用
这样子上个页面的参数可以保存在这个页面,为下个页面获取参数做准备,在这个页面表单提交的时候下个页面可以获取参数
- Unity3D GUI学习之GUI窗口的使用
GUI还可以定义一个窗口,在窗口里面进行控件的添加: using UnityEngine; using System.Collections; public class getbutton : Mon ...
- R文件丢失异常原因汇总
引言: R文件丢失异常在java开发中是个比较常见的异常,造成这个异常的原因可能非常微小,但是给Android开发者们造成的麻烦可是巨大的,当程序员们费尽千辛万苦,找到自己错在哪里的时候,绝对会对自己 ...