我们不难发现先被切开的两半一定比后被切开的两半大,这样就天然的生成了队列的单调性,就可以省去一个log。所以,我们开三个队列,分别为origin,big,smallorigin, big, smallorigin,big,small,每次查询时将三个队列的对头进行比较即可。

Code:

#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 500000 + 4;
bool cmp(int i,int j){return i > j;}
struct Node{
int length;
int pre;
Node(int length = 0, int pre = 0):length(length), pre(pre){}
};
queue<Node> small, big;
queue<int>origin;
priority_queue<int> fin;
int val[maxn];
int main()
{
// freopen("in.txt","r",stdin);
int n,m,p,u,v,t;
scanf("%d%d%d%d%d%d",&n,&m,&p,&u,&v,&t);
double perc = (double ) u / v;
for(int i = 1;i <= n; ++i)scanf("%d",&val[i]);
sort(val + 1,val + 1 + n, cmp);
for(int i = 1;i <= n; ++i)origin.push(val[i]);
for(int i = 1;i <= m; ++i)
{
int a = 0, b = 0, c = 0, ans;
if(!origin.empty()) a = origin.front() + p * (i - 1);
if(!small.empty()) b = small.front().length + (i - small.front().pre) * p;
if(!big.empty()) c = big.front().length + (i - big.front().pre) * p;
ans = max(a, max(b, c));
if(i % t == 0) printf("%d ",ans);
if(ans == a) origin.pop();
else if(ans == b) small.pop();
else big.pop();
int sm = floor((double)ans * perc) ;
int bm = ans - sm;
if(bm < sm) swap(bm,sm);
small.push(Node(sm,i + 1));
big.push(Node(bm,i + 1));
}
printf("\n");
while(!origin.empty()){ fin.push(origin.front() + p * (m)); origin.pop(); }
while(!small.empty()){ fin.push(small.front().length + p * (m - small.front().pre + 1)); small.pop();}
while(!big.empty()){ fin.push(big.front().length + p * (m - big.front().pre + 1)) ; big.pop();}
int cnt = 0;
while(!fin.empty())
{
++cnt;
if(cnt % t == 0) printf("%d ",fin.top());
fin.pop();
}
return 0;
}

洛谷P2827 蚯蚓 队列 + 观察的更多相关文章

  1. 洛谷P2827 蚯蚓 题解

    洛谷P2827 蚯蚓 题解 题目描述 本题中,我们将用符号 ⌊c⌋ 表示对 c 向下取整. 蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭蚯蚓. 蛐蛐国里现 ...

  2. 洛谷 P2827 蚯蚓 解题报告

    P2827 蚯蚓 题目描述 本题中,我们将用符号 \(\lfloor c \rfloor\) 表示对 \(c\) 向下取整,例如:\(\lfloor 3.0 \rfloor = \lfloor 3.1 ...

  3. NOIP 2016 洛谷 P2827 蚯蚓 题解

    题目传送门 展开 题目描述 本题中,我们将用符号[c]表示对c向下取整,例如:[3.0」= [3.1」=[3.9」=3.蛐蛐国最近蚯蚓成灾了!隔壁跳 蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手 ...

  4. 洛谷——P2827 蚯蚓

    P2827 蚯蚓 题目描述 本题中,我们将用符号 \lfloor c \rfloor⌊c⌋ 表示对 cc 向下取整,例如:\lfloor 3.0 \rfloor = \lfloor 3.1 \rflo ...

  5. 洛谷P2827 蚯蚓(单调队列)

    题意 初始时有$n$个蚯蚓,每个长度为$a[i]$ 有$m$个时间,每个时间点找出长度最大的蚯蚓,把它切成两段,分别为$a[i] * p$和$a[i] - a[i] * p$,除这两段外其他的长度都加 ...

  6. 洛谷P2827 蚯蚓——思路题

    题目:https://www.luogu.org/problemnew/show/P2827 思路... 用优先队列模拟做的话,时间主要消耗在每次的排序上: 能不能不要每次排序呢? 关注先后被砍的两条 ...

  7. 洛谷 P2827 蚯蚓

    题目描述 本题中,我们将用符号\lfloor c \rfloor⌊c⌋表示对c向下取整,例如:\lfloor 3.0 \rfloor= \lfloor 3.1 \rfloor=\lfloor 3.9 ...

  8. 洛谷p2827蚯蚓题解

    题目 算法标签里的算法什么的都不会啊 什么二叉堆?? qbxt出去学习的时候讲的,一段时间之前做的,现在才写到博客上的 维护3个队列,队列1表示最开始的蚯蚓,队列2表示每一次被切的蚯蚓被分开的较长的那 ...

  9. 洛谷 P2827 蚯蚓 题解

    每日一题 day32 打卡 Analysis 我们可以想一下,对于每一秒除了被切的哪一个所有的蚯蚓都增长Q米,我们来维护3个队列,队列1表示最开始的蚯蚓,队列2表示每一次被切的蚯蚓被分开的较长的那一部 ...

随机推荐

  1. 使用Layer完成图片放大功能

    序言:在写这个功能之前也用了zoom.js,zoom.js用起来简单引用js然后设置图片属性就可以放大.但是放大后的图片模糊.没有遮罩.在放大图片时其它图片布局会受到影响,当然如果觉得这些都是小问题的 ...

  2. Spring Cloud-个人理解的微服务演变过程(一)

    最初架构 说明:最初我们架构是垂直的 所有功能都在一个项目里面 随着业务和用户的增长 原来一台服务器已经不能支撑现有的请求数 这个时候我们就需要部署多台服务器 集群模式 说明:我们使用nginx做代理 ...

  3. MySQL:浅析 Impossible WHERE noticed after reading const tables

    使用 EXPLAIN 执行计划的时候,在 Extra 中偶尔会看到这样的描述: Impossible WHERE noticed after reading const tables 字面上的意思是: ...

  4. 0606关于mysql优化原理

    转自 http://blog.csdn.net/u012388497/article/details/25097159 本文通过一个案例来看看MySQL优化器如何选择索引和JOIN顺序.表结构和数据准 ...

  5. nginx中父子进程工作的主体函数

    依据Nginx(0.7.67版本号)的代码.对Nginx主要的进程创建,进程主体以及事件处理进行了简要的分析. 基本上,父进程(即主进程)一開始会初始化及读取配置.并载入各模块的功能,然后fork() ...

  6. 这篇文章关于两阶段提交和Paxos讲的很好

    http://blog.chinaunix.net/uid-16723279-id-3803058.html <两阶段提交协议与paxos投票算法> 点评:2PC绝对是CP的死党,是分布式 ...

  7. Eclipse快捷操作

    Eclipse快捷操作 快捷操作,包含了一些鼠标的操作: 学习了:http://www.cnblogs.com/iamfy/archive/2012/07/11/2586869.html 自己体会了一 ...

  8. &lt;LeetCode OJ&gt; 31. Next Permutation

    31. Next Permutation Total Accepted: 54346 Total Submissions: 212155 Difficulty: Medium Implement ne ...

  9. HTTP详解工作原理

    1. HTTP简介 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是用于从WWW服务器传输超文本到本地浏览器的传送协议.它可以使浏览器更加高效,使网络传输减少. ...

  10. java 10000的阶乘

    package test; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import ...