洛谷P2827 蚯蚓 队列 + 观察
我们不难发现先被切开的两半一定比后被切开的两半大,这样就天然的生成了队列的单调性,就可以省去一个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 蚯蚓 队列 + 观察的更多相关文章
- 洛谷P2827 蚯蚓 题解
洛谷P2827 蚯蚓 题解 题目描述 本题中,我们将用符号 ⌊c⌋ 表示对 c 向下取整. 蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭蚯蚓. 蛐蛐国里现 ...
- 洛谷 P2827 蚯蚓 解题报告
P2827 蚯蚓 题目描述 本题中,我们将用符号 \(\lfloor c \rfloor\) 表示对 \(c\) 向下取整,例如:\(\lfloor 3.0 \rfloor = \lfloor 3.1 ...
- NOIP 2016 洛谷 P2827 蚯蚓 题解
题目传送门 展开 题目描述 本题中,我们将用符号[c]表示对c向下取整,例如:[3.0」= [3.1」=[3.9」=3.蛐蛐国最近蚯蚓成灾了!隔壁跳 蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手 ...
- 洛谷——P2827 蚯蚓
P2827 蚯蚓 题目描述 本题中,我们将用符号 \lfloor c \rfloor⌊c⌋ 表示对 cc 向下取整,例如:\lfloor 3.0 \rfloor = \lfloor 3.1 \rflo ...
- 洛谷P2827 蚯蚓(单调队列)
题意 初始时有$n$个蚯蚓,每个长度为$a[i]$ 有$m$个时间,每个时间点找出长度最大的蚯蚓,把它切成两段,分别为$a[i] * p$和$a[i] - a[i] * p$,除这两段外其他的长度都加 ...
- 洛谷P2827 蚯蚓——思路题
题目:https://www.luogu.org/problemnew/show/P2827 思路... 用优先队列模拟做的话,时间主要消耗在每次的排序上: 能不能不要每次排序呢? 关注先后被砍的两条 ...
- 洛谷 P2827 蚯蚓
题目描述 本题中,我们将用符号\lfloor c \rfloor⌊c⌋表示对c向下取整,例如:\lfloor 3.0 \rfloor= \lfloor 3.1 \rfloor=\lfloor 3.9 ...
- 洛谷p2827蚯蚓题解
题目 算法标签里的算法什么的都不会啊 什么二叉堆?? qbxt出去学习的时候讲的,一段时间之前做的,现在才写到博客上的 维护3个队列,队列1表示最开始的蚯蚓,队列2表示每一次被切的蚯蚓被分开的较长的那 ...
- 洛谷 P2827 蚯蚓 题解
每日一题 day32 打卡 Analysis 我们可以想一下,对于每一秒除了被切的哪一个所有的蚯蚓都增长Q米,我们来维护3个队列,队列1表示最开始的蚯蚓,队列2表示每一次被切的蚯蚓被分开的较长的那一部 ...
随机推荐
- (16)Spring Boot使用Druid(编程注入)【从零开始学Spring Boot】
在上一节使用是配置文件的方式进行使用druid,这里在扩散下使用编程式进行使用Druid,在上一节我们新建了一个类:DruidConfiguration我在这个类进行编码: package com.k ...
- A - 敌兵布阵(HDU 1166)
A - 敌兵布阵 HDU - 1166 思路:线段树单点修改+区间查询. #include<cstdio> #include<cstring> #include<iost ...
- ELK 聚合查询
在elasticsearch中es支持对存储文档进行复杂的统计.简称聚合. ES中的聚合被分为两大类. 1.Metrics, Metrics 是简单的对过滤出来的数据集进行avg,max等操作,是一个 ...
- android 软键盘的显示与隐藏问题的研究
在android中,常常会和输入法的软件键盘交互.在Manifest文件中,系统给activity的一个属性-windowSoftInputMode来控制输入法的显示方式. 该属性提供了Activit ...
- 链表快排 & 基于链表的排序
以前只知道链表做插入(朴素.非二分)排序挺方便的.现在知道了(单)链表进行快速排序也是很好的(只是跟一般的快排的方式不一样). 参考: http://blog.csdn.net/otuhacker/a ...
- 关于在linux下出现stdio.h文件不存在等gcc标准库不能找到的解决的方法
首先说明一下我的系统配置:ubuntu 12.04 gcc 4.6.3 有几天没有使用ubuntu了,今天拿出来编程序,刚開始编译一个uboot1.1.6的代码.出现了stdio.h:没有那么 ...
- 【android】uses-permission和permission具体解释
1.<uses-permission>: 官方描写叙述: If an application needs access to a feature protected by a permis ...
- TI C66x DSP 系统events及其应用 - 5.6(INTMUX)
系统event 0~127(包含了eventCombiner的输出event 0~3)与CPU支持的12个可屏蔽中断是通过INTMUX寄存器进行映射的(不包含NMI.RESET).能够选择将系统eve ...
- HDU 5291(Candy Distribution-差值dp)
Candy Distribution Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- ASP怎样检測某目录是否存在,不存在则自己主动创建
ASP怎样检測某目录是否存在,不存在则自己主动创建 folder=server.mappath("/imagess") Set fso = CreateObject(" ...