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个数字,现 ...
随机推荐
- Android常用网址[转]
转自:http://my.oschina.net/u/593225/blog/404423 1.AndroidDevTools URL: http://www.androiddevtools.cn/ ...
- Android无法更新sdk的解决办法
修改 windows/system32/drivers/etc/hosts 文件 添加 203.208.46.146 dl.google.com203.208.46.146 dl-ssl.google ...
- OpenSSL使用指南
OpenSSL使用指南 1 介绍 OpenSSL是使用非常广泛的SSL的开源实现.由于其中实现了为SSL所用的各种加密算法,因此OpenSSL也是被广泛使用的加密函数库. 1.1 SSL ...
- 关于TXT转CHM的完整解决方式
为什么要转CHM? 有些书,TXT的资源非常好找,而CHM的资源非常难找(先不论PDF格式的,只是话说PDF格式的没有一个书签文件夹看起来也非常难受) 而CHM格式在左側有一个文件夹结构,我最喜欢这个 ...
- ExtractFileDir 与 ExtractFilePath 的差别
ExtractFileDir 与 ExtractFilePath 的差别 ExtractFileDir 从文件名称中获取文件夹名(文件不在根文件夹下时取得的值后没有"/",在根文件 ...
- systemtap分析软raid io拆分问题
http://www.sysnote.org/2014/05/01/systemtap-analysis-mdraid-io/
- iOS中__block 关键字的底层实现原理
在 <iOS面试题集锦(附答案)> 中有这样一道题目: 在block内如何修改block外部变量?(38题)答案如下: 默认情况下,在block中访问的外部变量是复制过去的,即:写操作不对 ...
- new Integer(1)和Integer.valueOf(1)的区别
java.lang包中的Integer类是我们比较常用的类,比如以下代码: Integer a=new Integer(1) Integer a=Integer.valueOf(1); 两个都是得到一 ...
- MVC+MEF+UnitOfWork+EF架构,网站速度慢的原因总结!(附加ANTS Memory Profiler简单用法)
(最近使用内存分析工具ANTS Memory Profiler,以及其他网友提供的意见发现最终导致内存泄漏的就是MEF,在此特地更新下,与大家分享!最下面红色字体) 最近参考使用了郭明峰的一套架构来做 ...
- WPF FindName()查找命名注册的元素
一.查找xaml中命名注册的元素 <Button x:Name="btn1" Content="显示内容" HorizontalAlignment=&qu ...