Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
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 MB
Submit: xxx Solved: 2xx
题目连接
http://codeforces.com/contest/529/problem/E
Description
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
Sample Input
- 6 20
10 50 100 500 1000 5000
8
4200
100000
95000
96000
99000
10100
2015
9950
- 5 2
1 2 3 5 8
8
1
3
5
7
9
11
13
15
Sample Output
- 6
20
19
20
-1
3
-1
-1
- 1
1
1
2
2
2
2
-1
HINT
题意:
有n种纸币,选择其中的两类纸币,最多拿m张,问最少多少张能够组成规定的面额
不能的话,就输出-1
题解:
暴力求解!
直接暴力枚举第一种钱,然后再暴力枚举第二种钱就好啦~
~\(≧▽≦)/~啦啦啦,这道题完啦
代码:
- //qscqesze
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <sstream>
- #include <queue>
- #include <typeinfo>
- #include <fstream>
- #include <map>
- typedef long long ll;
- using namespace std;
- //freopen("D.in","r",stdin);
- //freopen("D.out","w",stdout);
- #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
- #define maxn 50001
- #define mod 10007
- #define eps 1e-9
- //const int inf=0x7fffffff; //无限大
- const int inf=0x3f3f3f3f;
- /*
- */
- //**************************************************************************************
- map<int,int>s;
- inline int read()
- {
- int x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- int a[maxn];
- int main()
- {
- int n=read(),m=read();
- for(int i=;i<n;i++)
- {
- a[i]=read();
- s[a[i]]=;
- }
- int q=read();
- while(q--)
- {
- int ans=maxn;
- int k=read();
- for(int i=;i<n;i++)
- {
- for(int j=;j<=m;j++)
- {
- //cout<<a[i]*j<<endl;
- if(a[i]*j>k)
- break;
- if(a[i]*j==k)
- ans=min(ans,j);
- for(int t=;t<=m-j;t++)
- {
- if(((k-a[i]*j)%t)==)
- {
- if(s.count((k-a[i]*j)/t)==)
- ans=min(ans,j+t);
- }
- }
- }
- }
- if(ans==maxn)
- printf("-1\n");
- else
- printf("%d\n",ans);
- }
- }
Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!的更多相关文章
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题
E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp
题目链接: http://codeforces.com/problemset/problem/533/B B. Work Group time limit per test2 secondsmemor ...
- VK Cup 2015 - Round 1 E. Rooks and Rectangles 线段树 定点修改,区间最小值
E. Rooks and Rectangles Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemse ...
- VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串
题目链接:http://codeforces.com/contest/533/problem/E E. Correcting Mistakes time limit per test 2 second ...
- VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线
题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可 先考虑第一种情况, 第二种类似,sw ...
- VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)
VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) 代码 VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) A ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!
Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths
题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: ...
- codeforces VK Cup 2015 - Qualification Round 1 B. Photo to Remember 水题
B. Photo to Remember Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/522/ ...
随机推荐
- aarch64_g4
golang-github-inconshreveable-muxado-devel-0-0.7.gitf693c7e.fc26.noarch.rpm 2017-02-11 16:47 30K fed ...
- 博客转移至github
博客转移到github 鉴于github的各种优势,博客转移!
- 【oracle】入门学习(二)
oracle登录身份有三种:normal 普通身份sysdba 系统管理员身份sysoper 系统操作员身份每种身份对应不同的权限 sysdba权限:●启动和关闭操作●更改数据库状态为打开/装载/备份 ...
- OA项目Ioc DI(二)
依赖注入:属性和构造函数的注入 一个简单的Demo: IUserInfoDal接口: public interface IUserInfoDal { void Show(); string Name ...
- CF GYM100548 (相邻格子颜色不同的方案数 2014西安现场赛F题 容斥原理)
n个格子排成一行,有m种颜色,问用恰好k种颜色进行染色,使得相邻格子颜色不同的方案数. integers n, m, k (1 ≤n, m ≤ 10^9, 1 ≤ k ≤ 10^6, k ≤ n, m ...
- jquery选择里存在特殊字符,需要加双转义字符
//元素为:<input type="checkbox" value="abc/index" /> //处理选择器转义问题 //去除值 $val = ...
- Observer 观察者
意图 定义对象间的一种一对多的依赖关系 ,当一个对象的状态发生改变时, 所有依赖于它的对象都得到通知并被自动更新. 动机 一致性,松耦合 需要维护相关对象间的一致性.我们不希望为了维持一致性而使各类紧 ...
- vue2.0组件通信各种情况总结与实例分析
Props在vue组件中各种角色总结 在Vue中组件是实现模块化开发的主要内容,而组件的通信更是vue数据驱动的灵魂,现就四种主要情况总结如下: 使用props传递数据---组件内部 //html & ...
- 【AtCoder】AGC011 D - Half Reflector
题解 大意是n个管子排成一排,每个管子有两种状态,A状态是从某个方向进去,从原方向出来,B状态是从某个方向进去,从另一个方向出来 球经过一个A状态的管子这个管子会立刻变成B状态,经过一个B状态的管子会 ...
- python IDE之sublime真是个好东东
简捷轻爽,代码自动补齐.很好用. python3 { "shell_cmd": "python3 -u \"$file\"", " ...