Color the fence

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述

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=5,array={2,3,24,32,31,14,15,7,9},
虽然可以得到最长长度是2,且由除以2可得到结果11,但是最优的结果却是21。所以只要我们能
保证我们得到的高位数字比选择最小的数所得高位数字大并且位数相等即可。 AC代码:
 #include <stdio.h>

 int main(void)
{
int V;
while (~scanf("%d", &V))
{
int array[],i;
int min = ;
for (i = ; i <= ; i++)
{
scanf("%d", &array[i]);
if (array[i] <= min)
{
min = array[i];
}
} if (min > V)
{
printf("-1\n");
continue;
}
int bit = V / min;
while(bit--)
{
for (int j = ; j >= ; j--)
{
if (V >= array[j] && (V - array[j] )/ min == bit)
{
printf("%d", j);
V -= array[j];
break;
}
}
}
putchar('\n');
}
return ;
}
 

NYOJ-791 Color the fence (贪心)的更多相关文章

  1. nyoj 791——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. Codeforces 349B - Color the Fence

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

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

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

  5. nyoj Color the fence

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

  6. ACM Color the fence

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

  7. 349B - Color the Fence

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

  8. 【贪心】Codeforces 349B.Color the Fence题解

    题目链接:http://codeforces.com/problemset/problem/349/B 题目大意 小明要从9个数字(1,2,--,9)去除一些数字拼接成一个数字,是的这个数字最大. 但 ...

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

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

随机推荐

  1. 获取checked的值

    <div class="rule-multi-porp"> <span> <%var itemList = PublicQuery.GetItemLi ...

  2. ES 6 : Math对象的扩展

    ES6在Math对象上新增了17个与数学相关的方法.所有这些方法都是静态方法,只能在Math对象上调用. 1.Math.trunc() Math.trunc方法用于去除一个数的小数部分,返回整数部分. ...

  3. flex flashplayer 程序 和 air 程序 通过 LocalConnection 通信

    flashplayer 做控制端: <?xml version="1.0" encoding="utf-8"?> <s:Application ...

  4. JNDI实现服务器(tomcat)与数据库(mysql)连接的数据源配置以及获取连接的java代码

    ->首先将mysql的jar包导入到tomcat/lib文件夹下 ->然后在tomcat/conf/context.xml文件中配置以下内容 <Resource name=" ...

  5. centos redis 安装

    # wget http://download.redis.io/releases/redis-2.8.6.tar.gz # tar xzf redis-2.8.6.tar.gz # cd redis- ...

  6. redhat nginx 启动脚本

    #!/bin/sh # # nginx - this script starts and stops the nginx daemin # # chkconfig: - 85 15 # descrip ...

  7. 1.1 Eclipse下载安装

    可直接上官网下载:http://www.eclipse.org/downloads/ 直接下载地址:http://www.eclipse.org/downloads/download.php?file ...

  8. Oracle Day09 存储与触发器

    1.存储 存储过程.存储函数:指存储在数据库中供所有用户程序调用的子程序. --创建存储过程(procedure) --用create procedure 命令建立存储过程. 格式: create o ...

  9. stm32 串口乱码的解决

    版权声明:本文为博主原创文章. 前几天在中移物联网申请了一个迷你开发板,运行官方提供的程序,感觉板子是正常的.但是自己写的程序能够刷到板子上,但是串口却是乱码.官方和我的额程序都是用的库函数的方式写的 ...

  10. 转: Executor类

    Executor框架是指java 5中引入的一系列并发库中与executor相关的一些功能类,其中包括线程池,Executor,Executors,ExecutorService,Completion ...