Coins and Queries(codeforce 1003D)】的更多相关文章

Polycarp has nn coins, the value of the i-th coin is aiai . It is guaranteed that all the values are integer powers of 22 (i.e. ai=2dai=2d for some non-negative integer number dd ). Polycarp wants to know answers on qq queries. The jj -th query is de…
Coins and Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Polycarp has nn coins, the value of the ii-th coin is aiai. It is guaranteed that all the values are integer powers of 22 …
Polycarp has n coins, the value of the i-th coin is ai. It is guaranteed that all the values are integer powers of 2 (i.e. ai=2d for some non-negative integer number d). Polycarp wants to know answers on q queries. The j-th query is described as inte…
题目链接 题目大意:给你n个物品,第iii个物品价值aia_iai​,询问q次,问你能不能凑出价值为qiq_iqi​的物品. 小贪心吧.从大到小找,能拿就拿就行了. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; LL gcd(LL a,LL b){retur…
题意 n个硬币,q次询问.第二行给你n个硬币的面值(保证都是2的次幂!).每次询问组成b块钱,最少需要多少个硬币? Example Input 5 42 4 8 2 4851410 Output 1-132 解题思路:总体上使用的是贪心策略,从最大面值的往下贪心选择就可以了,由于数据量较大这里使用了map,这样就最多才32个数.第一次使用map的迭代器 反向迭代器的rbegin和rend的位置 和正向迭代器的begin和end的位置如下图   #include<cstdio> #include…
题意:给你一组全是\(2^d\ (d\ge0)\)的数,询问q次,每次询问一个数,问这个数是否能够由原数组中的数相加得到,如果能,输出最少用多少个数,否则输出\(-1\). 题解:首先贪心得出结论:如果情况成立,那么最少的情况一定是优先用数组中大的数,然后我们用桶记录数组数的个数,从\(inf\)开始枚举,\(k\)表示桶中的数和\(x\)所需次数的最小值,最后如果\(x\ne 0\)那么条件不满足,否则输出\(ans\)即可. 代码: #include <iostream> #include…
链接:http://codeforces.com/contest/1003 A. Polycarp's Pockets 题型:模拟 题意:把初始集合拆分,要求相同的数不在同一个集合中,求出需要的集合个数. 原因:WA-3,<=又不小心写成<+... B. Binary String Constructing 题型:构造 题意:给出a个0,b个1,用所有数字构造一个01串s,使得s中si≠si+1的情况数为x 原因:题意读错,以为要求出所有符合要求的串. 题解(别人清晰简单):https://b…
D. Coins and Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Polycarp has nn coins, the value of the ii-th coin is aiai. It is guaranteed that all the values are integer powers of …
目录 Codeforces 1003 A.Polycarp's Pockets B.Binary String Constructing C.Intense Heat D.Coins and Queries E.Tree Constructing(贪心) F.Abbreviation Codeforces 1003 比赛链接 这么做是不是不太好啊233 A.Polycarp's Pockets #include <cstdio> #include <cctype> #include…
打2017icpc沈阳站的时候遇到了大数的运算,发现java与c++比起来真的很赖皮,竟然还有大数运算的函数,为了以后打比赛更快的写出大数的算法并且保证不错,特意在此写一篇博客, 记录java的大数运算,也算是ACM java写法的入门: 学习博客:https://www.cnblogs.com/wkfvawl/p/9377441.html 进入到eclipse界面 第一步:file->new->java project->起名->finish 第二步:进入到刚才建的工程里,右键s…