E - Post Lamps

思路:一开始看错题,以为一个地方不能重复覆盖,我一想值这不是sb题吗,直接每个power check一下就好。。。。复杂度nlogn

然后发现不是,这样的话,对于每个power,假如我们覆盖到了x,那么我们要找到一个最大的 p <= x 且p 可以放灯,那么转移到的

为止为p + power,这样的话我想复杂度就变成了不是严格的nlogn,但是我写了一发还是过了,我感觉是复杂度接近nlogn,感觉没有

数据能把每个power的check都卡成n。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int> > using namespace std; const int N = 1e6 + ;
const int M = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n, m, k, s[N], a[N], p[N];
bool b[N];
LL ans = -;
int main() {
scanf("%d%d%d", &n, &m, &k); for(int i = ; i <= m; i++) {
scanf("%d", &s[i]);
b[s[i]] = true;
} for(int i = ; i <= k; i++) {
scanf("%d", &a[i]);
} if(b[]) {
puts("-1");
return ;
}
int pre = ;
for(int i = ; i < n; i++) {
if(!b[i]) pre = i;
p[i] = pre;
} for(int i = ; i <= k; i++) {
bool flag = true;
LL ret = ;
int j = ;
while(j < n) {
if(p[j] + i <= j) {
flag = false;
break;
}
j = p[j] + i;
ret += a[i];
}
if(flag) {
if(ans == - || ret < ans) {
ans = ret;
}
}
} printf("%lld\n", ans);
return ;
}
/*
*/

Educational Codeforces Round 45 (Rated for Div. 2) E - Post Lamps的更多相关文章

  1. Educational Codeforces Round 45 (Rated for Div. 2) C、D

      C. Bracket Sequences Concatenation Problem time limit per test 2 seconds memory limit per test 256 ...

  2. Educational Codeforces Round 45 (Rated for Div. 2) G - GCD Counting

    G - GCD Counting 思路:我猜测了一下gcd的个数不会很多,然后我就用dfs回溯的时候用map暴力合并就好啦. 终判被卡了MLE.....  需要每次清空一下子树的map... #inc ...

  3. Educational Codeforces Round 45 (Rated for Div. 2) F - Flow Control

    F - Flow Control 给你一个有向图,要求你给每条边设置流量,使得所有点的流量符合题目给出的要求. 思路:只有在所有点的流量和为0时有解,因为增加一条边的值不会改变所有点的总流量和, 所以 ...

  4. Educational Codeforces Round 45 (Rated for Div. 2)

    A bracket sequence is a string containing only characters "(" and ")". A regular ...

  5. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  6. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  7. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  8. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  9. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

随机推荐

  1. RACCommand中的信号

    示例: RACSignal* textSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscri ...

  2. [LeetCode] 398. Random Pick Index ☆☆☆

    Given an array of integers with possible duplicates, randomly output the index of a given target num ...

  3. js加载超时 nginx静态资源

    server { listen ; server_name www.example.com; client_max_body_size 20M; root /xxx/xxx;//项目路径 locati ...

  4. ZeroMQ API(八) 异常&属性

    1.错误处理 1.1 zmq_errno() 1.1.1 名称 zmq_errno - 为调用线程检索errno的值 1.1.2 概要 int zmq_errno(void); 1.1.3 描述 zm ...

  5. Django 2.0.1 官方文档翻译: 编写你的第一个 Django app,第二部分(Page 7)

    编写你的第一个 Django app,第二部分(Page 7)转载请注明链接地址 本教程上接前面的教程.我们会配置数据,创建你的第一个 model,并对Django 自动生成的 admin 站点进行快 ...

  6. 《java语言程序设计》初步学习——各种小Demo

    发现现在的天下几乎都是java的天下啊,虽然我个人对java没什么好感,但是迫于生活压力,还是学一下吧,我关注的应该主要还是web方面,所以应该学的是 java server page(JSP),所以 ...

  7. c++模板函数作为参数的疑惑

    为什么22行只能传一个模板函数作为参数,而非模板却编译失败,求解释.

  8. linux源码安装 rpm命令

    安装dhcp为例: 挂载光盘文件到/media目录 #mount /dev/sr0 /media 打开/media目录下的Packages目录 #cd /media/Packages 查看系统是否安装 ...

  9. windbg分析net程序内存泄漏问题

    1       问题简介 有客户反馈,打了最新补丁后,服务器的内存暴涨,一直降不下来,程序非常卡.在客户的服务器上抓了一个dump文件,开始分析. 分析问题的思路: 1.找到是那些资源占用了大量内存? ...

  10. 对web标准的理解,以及对w3c组织的认识

    (1)web标准规范要求,书写标签必须闭合.标签小写.不乱嵌套,可提高搜索机器人对网页内容的搜索几率.--- SEO(2)建议使用外链css和js脚本,从而达到结构与行为.结构与表现的分离,提高页面的 ...