Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
2015-03-25 23:55
579 查看
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/problem/EDescription
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 Input
Input6 20 10 50 100 500 1000 5000 8 4200 100000 95000 96000 99000 10100 2015 9950
Input
5 2 1 2 3 5 8 8 1 3 5 7 9 11 13 15
Sample Output
Output6 20 19 20 -1 3 -1 -1
Output
1 1 1 2 2 2 2 -1
HINT
[b]题意:[/b]有n种纸币,选择其中的两类纸币,最多拿m张,问最少多少张能够组成规定的面额
不能的话,就输出-1
[b]题解:[/b]
暴力求解!
直接暴力枚举第一种钱,然后再暴力枚举第二种钱就好啦~
~\(≧▽≦)/~啦啦啦,这道题完啦
[b]代码:[/b]
//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=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int a[maxn]; int main() { int n=read(),m=read(); for(int i=0;i<n;i++) { a[i]=read(); s[a[i]]=1; } int q=read(); while(q--) { int ans=maxn; int k=read(); for(int i=0;i<n;i++) { for(int j=1;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=1;t<=m-j;t++) { if(((k-a[i]*j)%t)==0) { if(s.count((k-a[i]*j)/t)==1) ans=min(ans,j+t); } } } } if(ans==maxn) printf("-1\n"); else printf("%d\n",ans); } }
相关文章推荐
- VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E---The Art of Dealing with ATM
- VK Cup 2015 - Round 1 C. The Art of Dealing with ATM
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数
- Codeforces VK Cup 2015 - Round 1 (Div.1 A~E)
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) A 水 B stl C stl D 暴力 E 树状数组
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp
- Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man
- Codeforces Round #277.5(Div. 2) D. Unbearable Controversy of Being【暴力】
- Codeforces Round #277.5 (Div. 2)D Unbearable Controversy of Being (暴力)
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers(STL_暴力)
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)A. Vicious Keyboard
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)-C. Voltage Keepsake
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) C Voltage Keepsake
- Codeforces Round #377 (Div. 2) Cormen --- The Best Friend Of a Man
- Codeforces Round #398(Div. 2)D. Cartons of milk【二分+暴力处理】
- Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心
- Codeforces Round #215 (Div. 1) C. Sereja and the Arrangement of Numbers(欧拉图)