VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E---The Art of Dealing with ATM

【codeforces VK Cup Round 1】BDE题解 codeforces VK Cup Round 1 BDE详细题解+代码~ 阅读详情

ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bills may be of at most two distinct denominations.

For example, if a country uses bills with denominations 10, 50, 100, 500, 1000 and 5000 burles, then at k = 20 such ATM can give sums 100 000 burles and 96 000 burles, but it cannot give sums 99 000 and 101 000 burles.

Let’s suppose that the country uses bills of n distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash q times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the q of requests for cash withdrawal.
Input

The first line contains two integers n, k (1 ≤ n ≤ 5000, 1 ≤ k ≤ 20).

The next line contains n space-separated integers ai (1 ≤ ai ≤ 107) — the denominations of the bills that are used in the country. Numbers ai follow in the strictly increasing order.

The next line contains integer q (1 ≤ q ≤ 20) — the number of requests for cash withdrawal that you will make.

The next q lines contain numbers xi (1 ≤ xi ≤ 2·108) — the sums of money in burles that you are going to withdraw from the ATM.
Output

For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print  - 1, if it is impossible to get the corresponding sum.
Sample test(s)
Input

6 20
10 50 100 500 1000 5000
8
4200
100000
95000
96000
99000
10100
2015
9950

Output

6
20
19
20
-1
3
-1
-1

Input

5 2
1 2 3 5 8
8
1
3
5
7
9
11
13
15

Output

1
1
1
2
2
2
2
-1

最多只能用2中面额的,用一个map搞搞就行了

/*************************************************************************
    > File Name: CF-VK-E.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com 
    > Created Time: 2015年03月23日 星期一 16时30分35秒
 ************************************************************************/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

vector <PLL> data;
map <int, int> mp;

int main()
{
    int n, k;
    while (~scanf("%d%d", &n, &k))
    {
        data.clear();
        mp.clear();
        int val;
        for (int i = 1; i <= n; ++i)
        {
            scanf("%d", &val);
            for (int j = 1; j <= 20; ++j)
            {
                data.push_back ( make_pair(val * j, j) );
                if (mp.find(val * j) == mp.end())
                {
                    mp[val * j] = j;
                }
                else
                {
                    mp[val * j] = min (mp[val * j], j);
                }
            }
        }
        sort(data.begin(), data.end());
        int m;
        scanf("%d", &m);
        while (m--)
        {
            scanf("%d", &val);
            int size = data.size();
            int ans = inf;
            for (int i = 0; i < size; ++i)
            {
                int now = data[i].first;
                int cnt1 = data[i].second;
                if (now == val)
                {
                    ans = min(ans, cnt1);
                }
                if (mp[val - now])
                {
                    ans = min(ans, mp[val - now] + cnt1);
                }
            }
            if (ans > k)
            {
                ans = -1;
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}
Codeforces Round #240 (Div. 1)B---Mashmokh and ACM(水dp) Mashmokh’s boss, Bimokh, didn’t like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh’s team. I 阅读详情

相关推荐

Codeforces Round #169 (Div. 2)---C. Little Girl and Maximum Sum(简单贪心)

The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you’ve got an array of n elements (the elements of the array are indexed starting from

Alex 1285

CF524C:The Art of Dealing with ATM(打表 + 二分)

C. The Art of Dealing with ATM time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ATMs of a ...

weixin_33800593的博客 189

手把手教你用STM32+LAN8720搭建以太网通信模块(含原理图)

本文详细介绍了如何使用STM32微控制器与LAN8720物理层芯片搭建以太网通信模块,涵盖硬件设计、软件配置及常见问题排查。重点讲解了LAN8720的低功耗设计、RMII接口简化布线等特性,以及STM32CubeMX配置和LwIP协议栈移植技巧,助力开发者快速实现稳定可靠的嵌入式网络通信。

CAT789的专栏 413

VK Cup 2015 - Round 1 C. The Art of Dealing with ATM

C. The Art of Dealing with ATM time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ATMs of a well-known bank of

WeYoungg的博客 576

RK3568/RK3588之修改8250驱动实现RS485收发的自动切换

在串口发送前,若为485,则将控制引脚拉为发送状态,在发送后,循环查看是否发送完成,若发送完成则将引脚置回读状态,如此一来,就能实现在内核测控制方向切换,而不会因为延时造成数据丢失,经过测试此办法可行。全部修改完成后,重新编译生成内核文件和设备树文件,烧写到板子上即可。

哒宰的博客 3117

如何用zemax导入solidworks装配体

在zemax使用中,常常需要导入各种零件。如果光机结构较为复杂,那么手工一个一个加载零件,还需要在zmx文件中调整object的位置,非常麻烦。如果能将solidworks的装配体模型直接导入,则可以大幅减小工作量。具体过程为(非序列模式下): 1、新建或打开一个zemax空文件 2、在元件编辑器中,找到一个空文件,双击或直接展开三角符,在类型中找到zemax里的solidworks装配体,如图。...

wojiaoyyy的博客 1万+

cf524C The Art of Dealing with ATM

ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is direc...

weixin_30242907的博客 208

transformer优化(一)-UNeXt 学习笔记

​它在早期阶段使用卷积,在潜在空间阶段使用 MLP。通过一个标记化的 MLP 块来标记和投影卷积特征,并使用 MLP 对表示进行建模。 ​

PLANTTHESON的博客 2033

VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp

B. Work Group time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One Big Software Company has n employees numb

习惯与规则决定命运 1065

基于STM32设计的4G远程视频侦查小车(图传+远程控制+EMQX+MQTT)(204)

当前设计了一款基于STM32F103ZET6主控芯片和废旧Android手机改造的4G侦查小车。该设计充分利用已有的智能手机硬件资源,实现摄像头画面的实时采集与上传,以及远程控制功能。这样的设计不仅降低了成本,而且充分利用了废旧手机中高性能的硬件资源,如摄像头、4G通信模块和电池等,实现了资源的有效循环利用。

2533

手把手教你学 Simulink (1.3)--Simulink 的模块库及其模块介绍

Simulink 提供了丰富的模块库,涵盖了从基本的信号生成和处理到复杂的数学运算和系统建模的各种功能。通过熟悉这些模块库及其模块,你可以更高效地构建和仿真动态系统。

MHD0815的博客 5150

Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing ...

VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/529/...

weixin_33705053的博客 101

组态王的日历时间控件脚本

日期时间控件中的脚本中在小于10的月份和天数前必须要加上0,这是由首字符对比机制规定的,首字母相同,就不再不做对比了,比如1和11,是一样的。首字母不同,再比较下一位。 float Ayear1; float Amonth1; float Aday1; string temp1; Ayear1=sd.Year; Amonth1=sd.Month; Aday1=sd.Day; temp1=StrFromInt( Ayear1, 10 ); if(Amonth1<10) temp1=temp1+"-0"+

逍遥子的博客 5718

自动化测试管理平台ATMS(V1.0.1_7.29)下载

自动化测试管理平台ATMS(V1.0.1_7.29)下载http://automationqa.com/forum.php?mod=viewthread&tid=2582&fromuid=29

软件质量优化 2615

Seurat-SCTransform与harmony整合学习

源于R tips:Seurat之SCTransform方法原理 (qq.com)Seurat对象在经过SCTransform处理后会增加一个SCT的Assay,里面的scaled.data就是经过scale之后的pearson residual值,这个值是用于后续降维聚类分析使用的。

hx2024的博客 2330

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

CodeForces 524 C.The Art of Dealing with ATM(枚举)

Description 一家银行的ATM机中有n种纸币,每种纸币面额为a[i],数量无限,但每次取款只能取最多k张最多两种面额的纸币,有q次查询,每次查询是否可以取x元,如果可以那最少取多少张纸币可以取到x元 Input 第一行两个整数n,k分别表示纸币种类数和每次取款数量上限,之后n个整数a[i]表示这n种纸币的面额,然后输入一整数q表示查询数,每次查询输入一整数x(1<=n<=5000,1

ZSQ 702

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Codeforces 529E The Art of Dealing with ATM 简单题

题目链接:点击打开链接 题意: 给定n种面额,每次ATM机能吐k张纸钞。(且每次ATM机只能吐至多2种面额) q个询问,每次回答若一次能吐出该面额的最少纸张数量,若不能则输出-1 O(n*k*k*logn)能过 #include #include #include #include #include #include #include #include #include templat

九野的博客 1448

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

VK Cup 2015 - Finals, online mirror

F. Clique in the Divisibility Graph题目传送:Clique in the Divisibility Graph解法:筛法+DPAC代码:#include <map> #include <set> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cstdio>

Never say never 902

Codeforces Round #177 (Div. 2)---D. Polo the Penguin and Houses (组合数学+暴力)

Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (

Alex 2169

ZeptoLab Code Rush 2015---C. Om Nom and Candies

A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with

Alex 1959

Codeforces Round #292 (Div. 1)---A. Drazil and Factorial

Drazil is playing a math game with Varda.Let’s define for positive integer x as a product of factorials of its digits. For example, .First, they choose a decimal number a consisting of n digits that co

Alex 1510

Codeforces Round #291 (Div. 2)---D. R2D2 and Droid Army

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputAn army of n droids is lined up in one row. Each droid is described by m integers a1,

Alex 1302

Codeforces Round #305 (Div. 2)C---Mike and Frog(扩欧+乱搞)

Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.So,

Alex 1292

Codeforces Round #177 (Div. 2)---E. Polo the Penguin and XOR operation(贪心)

Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive.For permutation p = p0, p1, …, pn, Polo has defined its beauty — number .Expression mean

Alex 1275

Codeforces Round #214 (Div. 2)---C. Dima and Salad

Dima, Inna and Seryozha have gathered in a room. That’s right, someone’s got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.Dima and Seryozha have n fruits i

Alex 1257
上一篇: Codeforces Round #117 (Div. 2)E---Wooden Fence(dp)
下一篇: Codeforces Beta Round #57 (Div. 2)E---Enemy is weak(树状数组+离散化)
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值