洛谷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表示每一次被切的蚯蚓被分开的较长的那一部 ...
随机推荐
- 如鹏网JAVA培训笔记1(晓伟整理)
JDK(Java Developmet Kit) JRE(Java RunTime Environment)的区别: JRE只有运行JAVA程序的环境,没有开发相关的工具;JDK=JRE+开发相关的工 ...
- vim编辑强制执行命令
vim进入文件,输入i编辑好文件,按esc,输入冒号,再输入底下代码 :w !sudo tee %
- hdu4762Cut the Cake(概率+大数操作(java)+C++高精度模板)
题目链接:点击打开链接 题目描写叙述:现有一个大蛋糕.上面随机分布了n个草莓,然后将草莓切成m块,问n个草莓全在一块蛋糕上面的概率? 解题思路:细致分析可得:C(n,1)/m^(n-1) 因为m< ...
- 单片机显示原理(LCD1602)
一.接口 LCD1602是很多单片机爱好者较早接触的字符型液晶显示器,它的主控芯片是HD44780或者其它兼容芯片.与此相仿的是LCD12864液晶显示器,它是一种图形点阵显示器,能显示的内容比LCD ...
- swift+moya URLCahe
1.定义获取缓存策略的接口 import Foundation protocol CachePolicyGettable { var cachePolicy: URLRequest.CachePoli ...
- RDLC报表钻取空白页问题
在改动报表查询条件时,钻取页突然空白了,百思不得其解,之前好好的,研究了一个下午和一个晚上.查资料等等,网上非常多资料都是设置报表的 ConsumeConteinerWhitespace = True ...
- Linux - shell壳脚本
shell脚本. 壳,充当一个翻译,让计算机能够认识的二进制程序,并将结果翻译给我们. 加在内核上,可以跟内核打交道的壳. 可以通过/etc/shells 来查看. [root@local ~]# c ...
- gcc 4.8安装
suse的安装参考:http://blog.csdn.net/cloudskyfhx/article/details/17660607 有些错误处理见本文黄色部分 CentOS 6.4 编译安装 gc ...
- JavaScript:对象
ylbtech-JavaScript:对象 1. JavaScript Array 对象返回顶部 1. JavaScript Array 对象 Array 对象 Array 对象用于在变量中存储多个值 ...
- 2.2.3 修改JSX代码
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { ...