Color the fence

2023-05-16

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.
样例输入

55 4 3 2 1 2 3 4 529 11 1 12 5 8 9 10 6  
样例输出

5555533  

一切皆在代码中(我加了足够的注释)

#include<stdio.h>

int main()
{
    int V;
    while(scanf("%d",&V) == 1)
    {
        int array[10];
        int min = 10001;
        for(int i = 1; i <= 9; 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 i = 9; i >= 1; i--)
            {
                if(V >= array[i] && (V - array[i]) / min == bit )
                {
                    printf("%d",i);
                    V -= array[i];
                    break;
                }
            }
        }
        printf("\n");
    }
    return 0;
}


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Color the fence 的相关文章

随机推荐

  • Python读写文件

    coding utf 8 向指定文件中存储指定内容 def text create name msg full path 61 name 43 39 txt 39 file 61 open full path 39 w 39 file wr
  • eclipse设置编码格式

    打开文件 xff0c 点击edit下的setCoding 如图 弹出一个对话框 xff0c 点击other 选择utf 8 先点击apply再点击OK 完成
  • Python打印九九乘法表

    打印九九乘法表 def create table for row in range 1 10 for column in range 1 row 43 1 print str row 43 39 39 43 str column 43 39
  • UVA10562解题报告

    我的GitHub地址 xff1a https github com DongChengrong ACM Program 仔细观察他给出的树 xff0c 我们可以发现这棵多叉树长得比较有特点 最上是树根 xff0c 而每一个节点只要有孩子下面
  • 实用函数之判断素数

    功能 xff1a 判断一个数是否是素数 素数概念 xff1a 只能被1和它本身整除的数 实现语言 xff1a C C 43 43 int is prime int n if n lt 61 1 return 0 int m 61 floor
  • 打不开IDLE

    我开始安装的是Python3 6 xff0c 后来发现很多库不支持3 6只支持2 7 xff0c 所以我又重装了2 7 xff0c 这时再打开IDLE就打不开了 经过我的几次努力终于找到了解决方案 将C盘 用户 xff08 user xff
  • Ubuntu系统中使用gdebi安装.deb文件

    传统软件套件管理工具 dpkg 定义 xff1a dpkg为 Debian 专门开发的套件管理系统 xff0c 方便软件的安装 更新及移除 首先 xff0c 要安装dpkg软件管理工具 suo span class token functi
  • IDLE设置字体大小

    点击option gt Configure 在出现的弹框里修改字体大小 xff0c 注意字体不能是楷体等与中文相关的字体 xff0c 否则点击OK无效 xff08 虽然在我电脑上确实是这样但是不知道为什么 xff0c 如果有知道的同学希望能
  • 关于递归问题的一点见解

    背景 前不久参加牛客网的有书共读活动意外的获得了一本 具体数学 xff0c 对此感谢牛客 其次领书是要条件的 xff0c 条件就是写读书笔记 搞ACM的都知道具体数学是本什么样的神书 xff08 也可能是我太弱了 xff09 xff0c 不
  • Python乱码问题

    原因 xff1a 源文件编码格式是UTF 8而Windows的编码格式是GBK xff0c 所以出现了乱码现象 解决方案一 xff1a 编码格式改成GBK就可以了 如下 第二种解决方案 coding utf 8 import sys typ
  • Python创建模块并导入

    Python创建自己的模块很方便 xff0c 所有的 py文件都被视为是一个模块 我们可以用import 文件名的方式把它导入自己的新文件 不过我们要注意创建的模块要符合命名规范 xff0c 比如首字母不能是数字等 如果首字母是数字就会出现
  • Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK

    现象 xff1a android util AndroidRuntimeException Calling startActivity from outside of an Activity context requires the FLA
  • Python查看库安装路径

    打开IDLE xff0c 输入如下两行指令 import sys print sys path 3 如下图
  • 安装pip教程

    相信在安装pip之前大家一定都安装了Python 所以我们找到Python的根目录下的Script文件夹 xff08 如果忘记了我们的安装目录可以参考文章http blog csdn net dongchengrong article de
  • pip常用指令

    安装库 xff1a pip install packageName flask 卸载库 xff1a pip uninstall packageName flask 升级库 xff1a pip install upgrade packageN
  • Python操作文件和目录

    对文件和目录进行操作是在我们开发过程中必不可少的一环 xff0c 下面是我整理的一些常用的对文件和目录进行操作的语句 xff0c 希望能帮到你 首先是导包 xff0c 导入包os xff0c import os 1 获取当前Python脚本
  • UVA227解题报告

    因为网格中存在空格所以用gets录入 xff0c 首先录入一行数据 xff0c 如果第一个字符为 39 Z 39 则break退出循环 其次是对指令的接受与处理 接受指令可以用getchar xff0c 遇到换行符跳过 处理也很简单 xff
  • win10/win11系统 如何将7-zip设置为默认软件?

    步骤 第一步 xff0c 首先下载7 zip第二步 xff0c 点击下载的7 zip安装包第三步 xff0c 进入你安装7 zip的文件夹下 xff0c 然后找到7 Zip File Manager第四步 xff0c 右键以管理员权限运行7
  • 南阳理工OJ915解题报告

    描述 Shiva得到了两个只有加号和减号的字符串 xff0c 字串长度相同 Shiva一次可以把一个加号和它相邻的减号交换 他想知道最少需要多少次操作才能把第一个字符串变换成第二个字符串 你现在要去帮助他完成那个这个问题 输入 多组测试数据
  • Color the fence

    Color the fence 时间限制 xff1a 1000 ms 内存限制 xff1a 65535 KB 难度 xff1a 2 描述 Tom has fallen in love with Mary Now Tom wants to s