Creative Snap

C. Creative Snap
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.

Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of 22. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following:

  • if the current length is at least 22, divide the base into 22 equal halves and destroy them separately, or
  • burn the current base. If it contains no avenger in it, it takes AA amount of power, otherwise it takes his B⋅na⋅lB⋅na⋅l amount of power, where nana is the number of avengers and ll is the length of the current base.

Output the minimum power needed by Thanos to destroy the avengers' base.

Input

The first line contains four integers nn, kk, AA and BB (1≤n≤301≤n≤30, 1≤k≤1051≤k≤105, 1≤A,B≤1041≤A,B≤104), where 2n2n is the length of the base, kkis the number of avengers and AA and BB are the constants explained in the question.

The second line contains kk integers a1,a2,a3,…,aka1,a2,a3,…,ak (1≤ai≤2n1≤ai≤2n), where aiai represents the position of avenger in the base.

Output

Output one integer — the minimum power needed to destroy the avengers base.

这题刚一看觉得很水

,仔细一看数据范围……

其实也不难,主要是数据范围过大。要用一种类似离散化的做法。

对数组a排序。对于一段区间[l,r]的英雄数量等于a中第一个比r大的数的下标减1减a中第一个大于等于l的数的下标加1,这样就可以做了(k很小)。

不过要注意剪枝:若区间[l,r]的英雄数量等于0,就直接返回A。

上代码:

#include <bits/stdc++.h>
using namespace std;
long long n, k, a, b;
long long hero[];
long long solve(long long l, long long r) {
long long num = upper_bound(hero + , hero + + k, r) - lower_bound(hero + , hero + + k, l);
if (num == ) return a;
long long ans = (r - l + ) * b * num;
if (l >= r) return ans;
ans = min(ans, solve(l, (l + r) / ) + solve((l + r) / + , r));
return ans;
}
int main() {
cin >> n >> k >> a >> b;
for (long long i = ; i <= k; i++) cin >> hero[i];
sort(hero + , hero + + k);
cout << solve(, ( << n));
}

Codeforces 1111C Creative Snap分治+贪心的更多相关文章

  1. 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 ...

  2. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  3. AcWing:105. 七夕祭(前缀和 + 中位数 + 分治 + 贪心)

    七夕节因牛郎织女的传说而被扣上了「情人节」的帽子. 于是TYVJ今年举办了一次线下七夕祭. Vani同学今年成功邀请到了cl同学陪他来共度七夕,于是他们决定去TYVJ七夕祭游玩. TYVJ七夕祭和11 ...

  4. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  5. Codeforces 437D The Child and Zoo - 树分治 - 贪心 - 并查集 - 最大生成树

    Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The ...

  6. Codeforces 888G Xor-MST - 分治 - 贪心 - Trie

    题目传送门 这是一条通往vjudge的高速公路 这是一条通往Codeforces的高速公路 题目大意 给定一个$n$阶完全图,每个点有一个权值$a_{i}$,边$(i, j)$的权值是$(a_{i}\ ...

  7. Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)

    题目链接:http://codeforces.com/problemset/problem/448/C C. Painting Fence time limit per test 1 second m ...

  8. Codeforces Round #537 C. Creative Snap

    题面: 传送门 题目描述: 灭霸想要摧毁复仇者联盟的基地.基地的长度为2的n次方,基地可以看成是一个长度为2的n次方的数组.基地的每一个位置可以由很多个超级英雄,但是一个超级英雄只能站一个位置.灭霸想 ...

  9. 【CodeCraft-19 and Codeforces Round #537 (Div. 2) C】Creative Snap

    [链接] 我是链接,点我呀:) [题意] 横坐标1..2^n对应着2^n个复仇者的基地,上面有k个复仇者(位置依次给出). 你是灭霸你要用以下方法消灭这k个复仇者: 一开始你获取整个区间[1..2^n ...

随机推荐

  1. Atcoder Grand Contest 037A(贪心,思维)

    #include<bits/stdc++.h>using namespace std;string s;char ans[200007][7];char anss[200007][7];i ...

  2. Android Dialog弹框提示

    public void showUpdateDialog(String content) { //普通的AlertDialog对话框 AlertDialog.Builder builder = new ...

  3. eclipse启动时权限不够的问题

    eclipse启动时权限不够的问题 2009年04月28日 19:19:00 tomey21 阅读数 1445   安装好后每次都要用root权限运行,比较郁闷,摸索了一下,修改一下相关目录的权限就可 ...

  4. macOS 10.14+ 安装LTP

    LTP是哈尔滨工业大学(HIT,窝工)出品的一个自然语言处理工具包.其功能包括中文分词(“分词效果好于jieba分词”[引用自学长]).词性标注.实体识别等. 对于macOS来说,现有的版本可能不多, ...

  5. 「CF126B」Password

    题目描述 给定一个字符串 \(S\),我们规定一个字符串 \(P\) 是可行解,\(P\) 需要满足: \(P\) 是 \(S\) 的前缀 \(P\) 是 \(S\) 的后缀 \(P\) 出现在 \( ...

  6. [Linux] day04——Linux 入门

    Linux 入门 =================Gnome 基于GTK图形库 速度快 稳定性好 专注与桌面本身 偏商务 RedHat企业版默认桌面KDE 基于QT 速度慢 软件多 习惯接近win ...

  7. 数字对象NSNumber的使用

    先简述下关于NSNumber的信息 NSNumber的存在就相当于java中的装箱与拆箱.只不过java中的装箱拆箱过程,使用的是对应的类型,比如基本数据类型是int.double类型,装箱时就得对应 ...

  8. Codeforces 1249E By Elevator or Stairs? 题解

    这题其实和 NIKKEI 2019-2-D Shortest Path on a Line 差不多的啦,都是一种最短路的变形,把多个点和边关联了起来. 题面 你要从一楼到 \(n\) 楼去,每层楼可以 ...

  9. rendering path定义了什么?有哪些?有什么作用?有什么限制?

    rendering path 定义了光照在一个shader pass中处理的对象与顺序,如逐像素处理,逐顶点处理,向前处理,后向 deferred用于处理不透明物体,会先把它们根据深度检测,过滤后的内 ...

  10. 在 Mac/Windows 系统中使用 Laradock 搭建基于 Docker 的 Laravel 开发环境 (改)

    开篇 Use Docker First And Learn About It Later 简介 Laradock 是为 Docker 提供的完整 PHP 本地开发环境,和 Homestead 一样提供 ...