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. [LeetCode] 208. Implement Trie (Prefix Tree) ☆☆☆

    Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...

  2. bzoj千题计划134:bzoj3124: [Sdoi2013]直径

    http://www.lydsy.com/JudgeOnline/problem.php?id=3124 第一问: dfs1.dfs2 dfs2中记录dis[i]表示点i距离最长链左端点的距离 第二问 ...

  3. CentOS 7快速入门系列教程(一)

    基本命令 ls 列举当前目录下的所有文件夹 ls -l 查看文件还是文件夹   d表示文件夹   -表示文件 ls --help man ls 询问命令 man 3 malloc 查看函数 cd 跳转 ...

  4. querySelectorAll 方法和 getElementsBy 系列方法的区别

    本文是我在知乎上的一个回答:http://www.zhihu.com/question/24702250/answer/28695133 ————— 下面是正文 ————— 1. W3C 标准quer ...

  5. jQuery精仿手机上的翻牌效果菜单

    代码简介: jQuery精仿手机上的翻牌效果菜单,很平滑的动画翻牌效果,每点击一下菜单,就会翻去一下,貌似很灵敏的动作.注意:如果预览时没看到效果,请刷新一下页面,让jquery载入就行了,在实际使用 ...

  6. 20155336 2016-2017-2《JAVA程序设计》第五周学习总结

    20155336 2016-2017-2<JAVA程序设计>第五周学习总结 教材学习内容总结 第八章 语法与继承构架 使用try.catch 特点: 使用try.catch语法,JVM会尝 ...

  7. weblogica domain目录 环境变量 如何启动weblogic server

    手工启动weblogic server

  8. Red Hat Enterprise Linux 7.2下使用RPM包安装SQL Server vNext

    1.下载安装包 mssql-server:https://packages.microsoft.com/rhel/7/mssql-server/ mssql-tools:https://package ...

  9. 【算法学习】【洛谷】树链剖分 & P3384 【模板】树链剖分 P2146 软件包管理器

    刚学的好玩算法,AC2题,非常开心. 其实很早就有教过,以前以为很难就没有学,现在发现其实很简单也很有用. 更重要的是我很好调试,两题都是几乎一遍过的. 介绍树链剖分前,先确保已经学会以下基本技巧: ...

  10. day09作业

    一.填空题 1.方法 2.堆内存 3.构造方法 4.this 5.this 6.static 7.使用类名进行访问 8.package import class 9.关键字 10.lang 二.选择题 ...