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 ...
随机推荐
- 微服务架构Day03-SpringBoot之web开发配置
概述 SpringBoot开发: 1.创建SpringBoot应用,选中需要的场景模块. 2.SpringBoot已经默认将场景模块配置好,只需要在配置文件中指定少量的配置(数据库地址,用户名,密码) ...
- woj1019 Curriculum Schedule 输入输出 woj1020 Adjacent Difference 排序
title: woj1019 Curriculum Schedule 输入输出 date: 2020-03-19 10:43:00 categories: acm tags: [acm,woj] 水题 ...
- HDU 4649 Professor Tian(概率DP)题解
题意:一个表达式,n + 1个数,n个操作,每个操作Oi和数Ai+1对应,给出每个操作Oi和数Ai+1消失的概率,给出最后表达式值得期望.只有| , ^,&三个位操作 思路:显然位操作只对当前 ...
- Storybook 最新教程
Storybook 最新教程 Storybook is the most popular UI component development tool for React, Vue, and Angul ...
- YouTube 视频下载工具
YouTube 视频下载工具 我不生产视频,只是优秀视频的搬运工! YouTube-dl https://github.com/search?q=youtube-dl https://github.c ...
- How to using PyPI publish a Python package
How to using PyPI publish a Python package PyPI & Python package https://pypi.org/ main make a f ...
- c++ winapi 在当前程序(local)调用目标程序(target)的函数
GameCheat stackoverflow 如果你的目标程序是x86/x64, 那么当前程序也需要编译为x84/x64 #include <iostream> #include < ...
- windows 隐藏desktop.ini文件
原文 在文件夹选项>查看 勾选"隐藏受保护的操作系统文件(推荐)"选项
- 比特币跌破3.5万美元,巨鲸们将目光瞄向SPC算力币
比特币最近又迎来了大幅下跌,截至周三(1月20日),比特币跌幅超过5%,跌破3.5万美元.很显然,比特币没有预期那样顺顺利利地登顶4万美元,反而又出现了回调迹象.有些巨鲸们在大肆囤币,然而也有些巨鲸们 ...
- C++算法代码——笨小猴
题目来自:http://218.5.5.242:9018/JudgeOnline/problem.php?id=1163 题目描述 笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼.但是他找到了 ...