Sand Fortress time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimens…
D - Sand Fortress 思路: 二分 有以下两种构造, 分别二分取个最小. 代码: #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp make_pair #define pb push_back #define ls rt<<1, l, m #defi…
题目链接:http://codeforces.com/contest/799/problem/C 题意:要求造2座fountains,可以用钻石,也可以用硬币来造,但是能用的钻石有限,硬币也有限,问能造出最大的美丽值为多少. 题解:显然如果两个fountains分别用钻石和硬币来造的话就直接取两种类型里满足条件的最大值即可. 如果选的是同类的话,先按照数量来排序,然后那一个数量为基准二分下个可行的数量,然后还需要一个 数组来存小于等于某个数量的最大美丽值. #include <iostream>…
传送门:送你去985D: 题意: 你有n袋沙包,在第一个沙包高度不超过H的条件下,满足相邻两个沙包高度差小于等于1的条件下(注意最小一定可以为0),求最少的沙包堆数: 思路: 画成图来说,有两种可能,一种是y=h-x一次函数和常函数y=x组合,还有一种是先上升后下降的函数,注意斜率绝对值都是1: 二分答案,具体来说,我是二分了最大高度,主要是check()比较要思考,(昨天晚上没有细心写check,错过了很多AC:): 这个check中:如果最大高度 mid 比m小,说明不会有折线,直接考虑三角…
A B /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a,b) make_pair(a,b) #define pb push_back ][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }}; using namespace std; typedef long long ll; inline v…
codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\(k\)满足:\[a_i \le k \le a_j\] 思路: 整体数组排序,对于当前\(a_i\)寻找符合条件的\(a_j\)的最大值和最小值 有:\[(a_i-1)/x+k=a_j/x\] 所以可以通过二分查找获得,这里我寻找\(((a_i-1)/x+k)*x\)为下界,\(((a_i-1)/x…
Description You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be described as a line of spots to pile up sand pillars. Spots are numb…
题目链接:http://codeforces.com/contest/862/problem/E 题解:水题显然利用前缀和考虑一下然后就是二分b的和与-ans_a最近的数(ans_a表示a的前缀和(奇加偶减)) #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; typ…
题目链接:http://codeforces.com/contest/814/problem/C 题意:给出一串字符串然后q个询问,问替换掉将m个字符替换为字符c,能得到的最长的连续的字符c是多长 题解:预处理dp[i][j]表示第i种字幕添加j个最长的连续为多长.然后与处理一下sum[j]表示前j个里有几个不是第i种字母的. 然后for一遍二分一下.更新dp. #include <iostream> #include <cstring> #include <vector&g…
题目链接:http://codeforces.com/contest/808/problem/E 题意:最多有100000个物品最大能放下300000的背包,每个物品都有权值和重量,为能够带的最大权值. 物品重量只有3中.重量为1,2,3. 题解:可以用3分写,这里先不介绍.主要讲一下二分+dp的方法.首先将重量为1,2,3的物品分别存下来, 然后从大到小排序一下.求一下前缀和,先将1,2二分,因为1,2的取法就两种要么取2,要么取两个1代替 2这里就需要二分,比较一下b[mid] and a[…