Codeforces Round #537 C. Creative Snap
题面:
题目描述:
题目分析:





1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <cmath>
5 #include <algorithm>
6 using namespace std;
7 const int maxn = 1e5+5;
8 long long n, k, A, B;
9 long long a[maxn];
10
11 long long binary(long long x){ //二分,左开右闭的设置
12 long long l = 0, r = k+1;
13 long long mid;
14 while(l < r){
15 mid = (l+r)/2; //左开右闭向下取整
16 if(a[mid] < x) l = mid+1;
17 else r = mid;
18 }
19 return l;
20 }
21
22 long long dfs(long long l, long long r){
23 int num = binary(r+1)-binary(l); //计算出位置区间[l, r]内的英雄个数
24
25 long long res;
26 if(!num) return A;
27 else res = B*num*(r-l+1);
28
29 if(l == r) return res; //递归终点
30 else return min(res, dfs(l, (l+r)/2)+dfs((l+r)/2+1, r)); //取小的作为结果
31 }
32
33 int main(){
34 cin >> n >> k >> A >> B;
35 for(int i = 1; i <= k; i++){
36 scanf("%lld", &a[i]);
37 }
38 sort(a+1, a+k+1);
39
40 //为了方便用二分而设置的
41 a[k+1] = 2e9;
42
43 long long r = (1<<n);
44
45 cout << dfs(1, r) << endl;
46 return 0;
47 }
Codeforces Round #537 C. Creative Snap的更多相关文章
- CodeCraft-19 and Codeforces Round #537 (Div. 2) C. Creative Snap 分治
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their bas ...
- 【CodeCraft-19 and Codeforces Round #537 (Div. 2) C】Creative Snap
[链接] 我是链接,点我呀:) [题意] 横坐标1..2^n对应着2^n个复仇者的基地,上面有k个复仇者(位置依次给出). 你是灭霸你要用以下方法消灭这k个复仇者: 一开始你获取整个区间[1..2^n ...
- CodeCraft-19 and Codeforces Round #537 (Div. 2) E 虚树 + 树形dp(新坑)
https://codeforces.com/contest/1111/problem/E 题意 一颗有n个点的树,有q个询问,每次从树挑出k个点,问将这k个点分成m组,需要保证在同一组中不存在一个点 ...
- CodeCraft-19 and Codeforces Round #537 (Div. 2) D 多重排列 + 反向01背包 + 离线处理
https://codeforces.com/contest/1111/problem/D 多重排列 + 反向01背包 题意: 给你一个字符串(n<=1e5,n为偶数),有q个询问,每次询问两个 ...
- CodeCraft-19 and Codeforces Round #537 Div. 2
D:即有不超过52种物品,求容量为n/2的有序01背包方案数.容易想到设f[i][j]为前i种物品已用容量为j的方案数,有f[i][j]=f[i-1][j-a[i]]*C(n/2-j+a[i],a[i ...
- CodeCraft-19 and Codeforces Round #537 (Div. 2) 题解
传送门 D. Destroy the Colony 首先明确题意:除了规定的两种(或一种)字母要在同侧以外,其他字母也必须在同侧. 发现当每种字母在左/右边确定之后,方案数就确定了,就是分组的方案数乘 ...
- CF#537 C. Creative Snap /// DFS
题目大意: 给定n k A B为位置长度 复仇者个数 两种花费 在一段为1~2^n的位置中 某些位置存在一些复仇者 求消灭所有复仇者的最小花费 对一段位置可以有两种处理方式 1.若该段长度至少为2 可 ...
- Codeforces 1111C Creative Snap分治+贪心
Creative Snap C. Creative Snap time limit per test 1 second memory limit per test 256 megabytes inpu ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- ArcGIS处理栅格数据(二)
五.栅格数据的配准 1.有参考图层 ① 在ArcMap里面添加需要配准的栅格数据集和参考数据集. ② 在ArcMap里面添加"地理配准"工具条. 添加成功后如下图所示: ③ 将需要 ...
- HEXO添加置顶功能
使用库:参考 http://wangwlj.com/2018/01/09/blog_pin_post/ 目前已经有修改后支持置顶的仓库,可以直接用以下命令安装.(cmd 到博客根目录,nmp运行) $ ...
- ARMv7-A 架构下的MMU
ARM架构中MMU的作用主要就是将CPU发出的虚拟地址转换成为物理地址,从实现内核和用户程序和用户程序之间的虚拟地址空间隔离.MMU的主要组成为两部分,其一是内部的TLBs缓存:还有就是转换表装换单元 ...
- MATLAB字符串分解, 合并
% 分解 % regexp s = 'ab/c/d.png' file_name = regexp(s, '/', 'split'); % 'd.png' % split fractions = sp ...
- H5 Funny Games All In One
H5 Funny Games All In One H5 游戏 盖楼 游戏 https://iamkun.github.io/tower_game/ https://github.com/iamkun ...
- DNS & HTTPS bug
DNS & HTTPS bug SSL protocol version bug https://typescript-4.x-tutorials.xgqfrms.xyz/ errors Th ...
- how to use brew install gpg
how to use brew install gpg https://formulae.brew.sh/formula/gnupg $ brew install gnupg https://gith ...
- 如何用 js 实现一个类似微信红包的随机算法
如何用 js 实现一个类似微信红包的随机算法 js, 微信红包, 随机算法 "use strict"; /** * * @author xgqfrms * @license MIT ...
- taro table component
taro table component https://juejin.im/post/5d901696f265da5b926bbcaa https://taro-ext.jd.com/search? ...
- 「NGK每日快讯」12.14日NGK公链第41期官方快讯!