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

传送门: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.商作为不可继…
Goodbye 2018 可能是我太菜考试的时候出不了$E$ 可能是我太菜考试的时候调不出$F$ 所以转化为手速场之后手速还上不去.jpg A 模拟题意... #include <cstdio> #include <algorithm> #include <cmath> using namespace std; int main() { int y,b,r,ans=1<<30; scanf("%d%d%d",&y,&b,&…
j题目链接: http://codeforces.com/contest/913/problem/E 题意: 给你x,y,z三个变量,与&   或|  非!  括号()   四种运算符,规定括号和非优先级最高,其次与&,最后或|. 对于输入的真值表,输出最小字典序的逻辑表达式 挺难想的.关键点在于怎么定义状态并利用已有状态更新出新状态,并处理优先级问题. 状态转移: 对于两个表达式A1,A2及其真值表T1,T2,若没有优先级的问题,A1&A2的真值表为T1&T2,A1|A2…
[题目]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/gym/102028 A. Xu Xiake in Henan Province 看起来像水题.乱搞一下,还真是. #include<bits/stdc++.h> using namespace std; #define ll long long int main(){ int n; while(~scanf("%d",&n)){ ;i<n;i++){ ; ;j<;j++){ int t; scanf(&quo…
2018.12.25 1.[BZOJ 4310] 2.[BZOJ 3879] 3.[BZOJ 2754] 4.[BZOJ 4698] 5.[Codeforces 914E] 6.[Codeforces 161D] 7.[Codeforces 716E] 2018.12.26 1.[ZROI #144] 2.[ZROI #145] 3.[ZROI #146] 4.[BZOJ 4199] 5.[BZOJ 3198] 6.[BZOJ 4182] 7.[BZOJ 4675] 2018.12.27 1.[…
Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/D Description Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive…
Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Pattern Matching 题意就是匹配字符的题目,打比赛的时候没有看到只有一个" * ",然后就写挫了,被hack了,被hack的点就是判一下只有一个" * ". 代码: //A #include<iostream> #include<cstdio>…
Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给出三堆数量分别为y,b,r的东西,现在要你从三堆中各选一堆,满足y'+1=b'且b'+1=r' (y',r',b'分别是指从中选取的个数). 现在问最多能拿出的个数为多少. 题解: 我是直接模拟的= =但是有更简单的方法. 让y+=2,b+=1,那么现在的最优解为min(y,b,r)*3-3.这个还…
C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search…
B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how…
A. k-rounding time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros i…
https://codeforces.com/contest/1056/problem/B 题意:输入n,m    求((a*a)+(b*b))%m==0的(a,b)种数(1<=a,b<=n) (n<=1e9,m<=1000) 题解:由于a,b的数量级很大,而m的数量级很小,又因为求((a*a)+(b*b))%m==0,即求((a%m*a%m)+(b%m*b%m))%m==0满足要求的a,b对数,也就是求a%m,b%m的平方分别取模后相加为0或者m的a,b对数,由于此时问题只和a%…
http://codeforces.com/contest/1054/problem/D 题目大意:一个序列a1 a2...an,可以对若干个元素进行取反,使所得的新序列异或和为0的区间个数最多. 题目分析:首先易知每个位置的前缀异或和的值只有两种,因为对元素进行取反时,取偶数个元素异或和不变,奇数个元素就是原值取反.然后由于对一个位置取反,不会影响后面位置与这个位置的前缀异或和相同的位置个数(因为这个位置取反后,后面各个位置的前缀异或和也跟着改变),所以一个位置的改变只会影响与前面位置前缀和相…
http://codeforces.com/contest/1025/problem/D 树 dp 优化 f[x][y][0]=f[x][z][1] & f[z+1][y][0] ( gcd(a[x-1],a[z])<>0 ) f[x][y][1]=f[x][z][1] & f[z+1][y][0] ( gcd(a[z],a[y+1])<>0 ) #include <cstdio> #include <cstdlib> #include &l…
http://codeforces.com/contest/967/problem/F 题目大意: 有n个点,n*(n-1)/2条边的无向图,其中有m条路目前开启(即能走),剩下的都是关闭状态 定义:从x走到y(即x->y)后,和x所连接的边的所有状态都反转(即开启->关闭,关闭->开启) 问,从起点1走到终点n,最少需要经过几步,并且输出这个路径(如果存在多挑最短路径,输出任意一条) 如果不存在,则输出-1 思路: 其实这道题第一眼看过去就是bfs,不过,由于每个状态都在改变,那要怎么…
http://codeforces.com/contest/967/problem/E 题目大意: 给你一个数组a,a的长度为n 定义:b(i) = a(1)^a(2)^......^a(i), 问,是否存在一种情况,使得a(i)重新排列以后以后,满足b(i)是严格单调递增的. 思路: 对于二进制位操作来说,如果异或后值增加,即 p^q > p,必然满足两种情况(假定一个为p,一个为q) ①q的最高位>p的最高位 ②q的最高位(假定第k为最高) < p的最高位,但是p的第k位为0 这样,…
A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个数的数字即在A数组中出现过,也在B数组中出现过,问这个数最小是多少. 题目思路:首先要么一个数两个数组都出现过直接输出来,要么分别取两个数组中最小的数组合一下输出. 代码: //Author: xiaowuga #include <bits/stdc++.h> using namespace st…
地址:http://codeforces.com/contest/872/problem/D 题目: D. Something with XOR Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. Jury has hidden a permutati…
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…
咕bye 2018,因为我这场又咕咕咕了 无谓地感慨一句:时间过得真快啊(有毒 A.New Year and the Christmas Ornament 分类讨论后等差数列求和 又在凑字数了 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a,b,c; int main() { scanf("%d%d%d",&a,&b,&…
http://codeforces.com/contest/1023/problem/E 交互题 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <time.h> #include <string> #include <set> #include <map> #include <list&g…
http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x2. 运行任务的条件: ①每个服务器只能同时运行一个任务 ②任务可以同时分配到多个服务器中执行.假设任务x1分配到a个服务器中,则每个服务器都需要使用x1/a的资源(该资源可以为小数) 问能否满足以上条件,使得x1,x2同时在服务器中运行? 思路: 将所有服务器按照资源增序排列,定义dp(i)表示从…
A. k-rounding 题目意思:给两个数n和m,现在让你输出一个数ans,ans是n倍数且末尾要有m个0; 题目思路:我们知道一个数末尾0的个数和其质因数中2的数量和5的数量的最小值有关系,所以我们可以把n中的2和5的因子数量分别算出来,然后看一下是否都大于等于m,否则我们就把他们补成m个.然后再乘回去就结束了. 题目链接:http://codeforces.com/contest/861/problem/A 代码: /* *********************************…
B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mat…
占坑,明天写,想把D补出来一起写.2/20/2018 11:17:00 PM ----------------------------------------------------------我是分割线------------------------------------------------------- 我来了,本来打算D题写到一起的,但是有新的东西要写,D就单独写一篇,这里写A,B,C: 开启智障模式:(看我咸鱼突刺的厉害( • ̀ω•́ )✧)   2/21/2018 10:46:…
http://codeforces.com/contest/948/problem/A   A. Protect Sheep Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his she…
题 OvO http://codeforces.com/contest/963/problem/B CF 963B 964D 解 对于题目要求,显然一开始的树,要求度数为偶数的节点个数为奇数个,通过奇偶讨论显然这个树总节点个数为奇数个. 然后对于每一步分割出来的树林,显然树林中每个树都得满足度数为偶数的节点个数为奇数个,同样地,可以得到树林中每个树的总结点为奇数个 其实上面写的一些是废话,后文并不会用到…… 首先排除度数为偶数的节点有偶数个的树,即已知要讨论的树均满足度数为偶数的节点有奇数个 从…
题: OvO http://codeforces.com/contest/947/problem/D 923D 947D 948E 解: 记要改变的串为 P1 ,记目标串为 P2  由变化规则可得: 1. B -> AC -> AAB -> AAAC -> C ( 即 B -> C -> B ) 2. AB -> AAC -> AAAB -> B (即 AB -> B ) 3. B -> AC -> AB ( 即 B -> AB…
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…