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的更多相关文章

  1. ACM Color the fence

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  2. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  3. NYOJ-791 Color the fence (贪心)

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  4. 349B - Color the Fence

    Color the Fence Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

  5. nyoj Color the fence

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  6. Codeforces 349B - Color the Fence

    349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...

  7. nyoj 791——Color the fence——————【贪心】

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  8. Codeforces D. Color the Fence(贪心)

    题目描述: D. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. B. Color the Fence

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  10. codeforces B. Color the Fence 解题报告

    题目链接:http://codeforces.com/problemset/problem/349/B 题目意思:给定v升的颜料和9个需要花费ad 升的颜料,花费ad 升的颜料意味着得到第d个数字,现 ...

随机推荐

  1. 还原virtual函数的本质-----C++

    当你每次看到C++类中声明一个virtual函数,特别是看到了一个virtual的虚构函数.你知道它的意思吗?你肯定会毫不犹豫的回答:不就是多态么...在运行时确定具体的行为么...完全正确,但这里我 ...

  2. Linux内核之mmc子系统-sdio

    现在的Linux内核中,mmc不仅是一个驱动,而是一个子系统.这里通过分析Linux3.2.0内核,结合TI的arm335x平台及omap_hsmmcd host分析下mmc子系统,重点关注sdio及 ...

  3. [CSS] @keyframes

    @keyframes swing{ 0% { transform: rotate(0deg)} 100% {transform: rotate(-30deg)} } #sweetlandia{ ani ...

  4. struts2 json 定义全局Date格式

    使用struts2的json插件时,自己定义日期格式经常使用的方式是在get属性上加入@JSON注解,这个对于少量Date属性还能够,可是假设date字段多了,总不可能去给每一个date get方法加 ...

  5. android 30 下拉列表框:ArrayAdapter和Spinner.

    package com.sxt.day05_04; import android.os.Bundle; import android.app.Activity; import android.cont ...

  6. 使用blktrace统计磁盘块I/O访问频率 + IO调度CFQ

    http://blog.chinaunix.net/uid-24774106-id-4096470.html http://blog.csdn.net/wyzxg/article/details/74 ...

  7. 基于hadoop2.6.0搭建5个节点的分布式集群

    1.前言 我们使用hadoop2.6.0版本配置Hadoop集群,同时配置NameNode+HA.ResourceManager+HA,并使用zookeeper来管理Hadoop集群 2.规划 1.主 ...

  8. 亲测linux上安装mysql

    1.rpm -ivh MySQL-server-5.6.19-linux_glibc2.5.x86_64.rpm(这是复制过来的,用Tab键自动补齐吧)2.rpm -ivh MySQL-client- ...

  9. 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之一

    /** ****************************************************************************** * @author    暴走的小 ...

  10. svn 设置钩子将代码同步到web目录下面

    首先:确定思路: 要在SVN服务中,找到仓库文件夹的位置,在相应的项目中找到hooks文件夹.在该文件中添加一个post-commit文件: 当有commit动作发生时(提交到SVN服务是就会执行这个 ...