Codeforces 913C - Party Lemonade】的更多相关文章

913C - Party Lemonade 思路:对于第i个话费cost[i],取min(cost[i],2*cost[i-1]),从前往后更新,这样就可以保证第n个的话费的性价比最高,那么从最高位开始贪心,取最优解. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) const ll…
链接:CodeForces - 913C 题意:给出 n 瓶饮料的花费 C 数组,每瓶的体积是 2^(i-1) 升,求至少买 L 升的最少花费. 题解:二进制数的组合可以表示任何一个数.第 i 的饮料的最少花费可以由 第 i-1 瓶得来.依次枚举每一瓶,取最小值. #include <bits/stdc++.h> using namespace std; ; const int INF = 0x3f3f3f3f; ; ; int n, L; int c[maxn]; int main() {…
C. Party Lemonade A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volume…
点完菜,他们发现好像觉得少了点什么? 想想马上就要回老家了某不愿透露姓名的林姓学长再次却陷入了沉思......... 他默默的去前台打算点几瓶二锅头. 他发现菜单上有n 种不同毫升的酒. 第 i 种有2i - 1 毫升价格为ci 元.商店中每种类型的酒的数量可以被认为是无限的.. 他对于自己能喝多少还是有点B-Tree的,但是他认为喝酒一定要喝的尽兴,于是他打算买至少L 毫升,但是又要花最少的钱,现在他想知道他最少需要花多少钱 Input 第一行输入两个整数 n and L (1 ≤ n ≤ 3…
[题目]C. Party Lemonade [题意]给定n个物品,第i个物品重量为2^(i-1)价值为ci,每个物品可以无限取,求取总重量>=L的最小代价.1<=30<=n,1<=L,ci<=10^9. [算法]数学(二进制原理) [题解]实际上每个物品的重量对应答案的一个二进制位,先对物品进行预处理: 1.将没用的大物品用小物品替代(价值不如前面的小物品叠加). 2.用单价最小的物品补齐后面的二进制位. 然后把L二进制展开,从小到大扫描:如果该位是1则必须选择该物品,如果该…
传送门:http://codeforces.com/contest/913/problem/C 有n类物品,第i(i=0,1,2,...,n-1)类物品的价值为2i,花费为ci.任意选择物品,使得总价值至少为L.求此时的总花费的最小值.(n≤30,L≤109,ci≤109) 这是一个完全背包问题,但是鉴于数据规模,常规的DP是不可取的(TLE+MLE). 首先考虑到的是递归地搜索答案.对于当前状态(cur,k),对价值cur做一个简单的划分:商q=cur/vi,余数r=cur%vi.商作为不可继…
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题.. 今天,我们来扒一下cf的题面! PS:本代码不是我原创 1. 必要的分析 1.1 页面的获取 一般情况CF的每一个 contest 是这样的: 对应的URL是:http://codeforces.com/contest/xxx 还有一个Complete problemset页面,它是这样的:…
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of bconsecutive cells. No cell can be part of two ships, however, the shi…
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's…
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters. There is…