[NOIp2016提高组]蚯蚓
题目大意:
给你n个不同长度蚯蚓,每秒从里面取出最长的砍下u/v变成两只,又把剩下的加长q。
问你在m之前的t,2t,3t...的时间上,砍的蚯蚓长度,
以及m秒后剩下所有的蚯蚓长度。
思路:
很容易想到用一个堆来解决,然而这样时间复杂度是O((m+n)log(m+n))的,过不去。
所以复杂度得是线性的。
考虑把原来的堆改成三个单调队列。
每个蚯蚓切成两半总会有一个长的、一个短的。
我们有q1维护原来的蚯蚓,q2维护砍下来长的一截蚯蚓,q3维护砍下来短的一截蚯蚓。
不考虑蚯蚓的生长,我们只需要每次砍完蚯蚓扔进去就可以了。
算长度只要把每个单位时间内增加的长度乘以时间加到蚯蚓上面就可以了。
注意中间结果开long long,不然只有70分。
#include<queue>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<functional>
typedef long long int64;
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=;
int a[N];
std::queue<int> q1,q2,q3;
inline int getmax() {
if(q1.empty()&&q2.empty()) {
const int ret=q3.front();
q3.pop();
return ret;
}
if(q1.empty()&&q3.empty()) {
const int ret=q2.front();
q2.pop();
return ret;
}
if(q2.empty()&&q3.empty()) {
const int ret=q1.front();
q1.pop();
return ret;
}
if(q1.empty()) {
if(q2.front()>q3.front()) {
const int ret=q2.front();
q2.pop();
return ret;
}
const int ret=q3.front();
q3.pop();
return ret;
}
if(q2.empty()) {
if(q1.front()>q3.front()) {
const int ret=q1.front();
q1.pop();
return ret;
}
const int ret=q3.front();
q3.pop();
return ret;
}
if(q3.empty()) {
if(q1.front()>q2.front()) {
const int ret=q1.front();
q1.pop();
return ret;
}
const int ret=q2.front();
q2.pop();
return ret;
}
if(q1.front()>=q2.front()&&q1.front()>=q3.front()) {
const int ret=q1.front();
q1.pop();
return ret;
}
if(q2.front()>=q1.front()&&q2.front()>=q3.front()) {
const int ret=q2.front();
q2.pop();
return ret;
}
if(q3.front()>=q1.front()&&q3.front()>=q2.front()) {
const int ret=q3.front();
q3.pop();
return ret;
}
return ;
}
int main() {
int n=getint(),m=getint(),q=getint(),u=getint(),v=getint(),t=getint();
for(register int i=;i<n;i++) {
a[i]=getint();
}
std::sort(&a[],&a[n],std::greater<int>());
for(register int i=;i<n;i++) {
q1.push(a[i]);
}
for(register int i=;i<=m;i++) {
const int max=getmax()+q*(i-);
if(!(i%t)) printf("%d ",max);
q2.push(std::max((int64)max*u/v-q*i,(int64)max-(int64)max*u/v-(int64)q*i));
q3.push(std::min((int64)max*u/v-q*i,(int64)max-(int64)max*u/v-(int64)q*i));
}
putchar('\n');
for(register int i=;!q1.empty()||!q2.empty()||!q3.empty();i++) {
const int max=getmax();
if(!(i%t)) printf("%d ",max+q*m);
}
return ;
}
[NOIp2016提高组]蚯蚓的更多相关文章
- Noip2016 提高组 蚯蚓
刚看到这道题:这题直接用堆+模拟不就可以了(并没有认真算时间复杂度) 于是用priority_queue水到了85分-- (STL大法好) 天真的我还以为是常数问题,于是疯狂卡常--(我是ZZ) 直到 ...
- Luogu P2827 [NOIp2016提高组]蚯蚓 | 神奇的队列
题目链接 80分思路: 弄一个优先队列,不停地模拟,切蚯蚓时就将最长的那一条出队,然后一分为二入队,简单模拟即可.还要弄一个标记,表示从开始到当前时间每一条蚯蚓应该加上的长度,操作时就加上,入队时就减 ...
- 洛谷P2827 [NOIP2016 提高组] 蚯蚓 (二叉堆/队列)
容易想到的是用二叉堆来解决,切断一条蚯蚓,其他的都要加上一个值,不妨用一个表示偏移量的delta. 1.取出最大的x,x+=delta: 2.算出切断后的两个新长度,都减去delta和q: 3.del ...
- 【题解】NOIP2016提高组 复赛
[题解]NOIP2016提高组 复赛 传送门: 玩具谜题 \(\text{[P1563]}\) 天天爱跑步 \(\text{[P1600]}\) 换教室 \(\text{[P1850]}\) 组合数问 ...
- 【题解】NOIP2016 提高组 简要题解
[题解]NOIP2016 提高组 简要题解 玩具迷题(送分) 用异或实现 //@winlere #include<iostream> #include<cstdio> #inc ...
- NOIP2016提高组解题报告
NOIP2016提高组解题报告 更正:NOIP day1 T2天天爱跑步 解题思路见代码. NOIP2016代码整合
- [日记&做题记录]-Noip2016提高组复赛 倒数十天
写这篇博客的时候有点激动 为了让自己不颓 还是写写日记 存存模板 Nov.8 2016 今天早上买了两个蛋挞 吃了一个 然后就做数论(前天晚上还是想放弃数论 但是昨天被数论虐了 woc noip模拟赛 ...
- 【NOIP2016提高组day2】蚯蚓
那么我们开三个不上升队列, 第一个记录原来的蚯蚓, 第二个记录乘以p的蚯蚓 第三个记录乘以(1-p)的蚯蚓, 在记录每条就要入队列的时间,就可以求出增加的长度 每次比较三个队列的队首,取最大的值x的切 ...
- 【NOIP2016提高组】 Day2 T2 蚯蚓
题目传送门:https://www.luogu.org/problemnew/show/P2827 自测时被题面所误导...,题面中说逢t的倍数才输出答案,以为有什么玄妙的方法直接将m次操作变成了m/ ...
随机推荐
- DesignPattern
目录
- 随机森林(Random Forest)详解(转)
来源: Poll的笔记 cnblogs.com/maybe2030/p/4585705.html 1 什么是随机森林? 作为新兴起的.高度灵活的一种机器学习算法,随机森林(Random Fores ...
- POJ1014(多重背包)
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65044 Accepted: 16884 Descri ...
- Django===django工作流
通过一张图来总结一下Django 的处理过程: URL 组成: 协议类型: HTTP/HTTPS HTTP 协议(HyperText Transfer Protocol,超文本传输协议)是用于从WWW ...
- linux-open-source-development-tools【重点】
https://www.pluralsight.com/blog/software-development/linux-open-source-development-tools https://ww ...
- sicily 1059. Exocenter of a Trian
Description Given a triangle ABC, the Extriangles of ABC are constructed as follows: On each side of ...
- 阿里云Centos等更新源设置成阿里源方法。
https://help.aliyun.com/knowledge_detail/5974184.html ---------------------------------------------- ...
- Python 什么是ORM?
关系映射 性能比源生sql效率略差一些 操作性更简单,快捷 Django的orm和sqlalchamy 区别 sqlalchamy没有django的功能全,不支持双下划线的连表跨表操作 sqlalch ...
- 使用dpkg命令卸载已经安装的软件包
如何在Ubuntu中使用dpkg命令卸载软件 http://jingyan.baidu.com/article/f54ae2fc2724a71e92b849c4.html sudo dpkg -i x ...
- hdu 5576 dp
题目大意:给你一个长度为 n 的 字符串表示一个乘法,一次操作随机选两个字符进行交换,进行m次操作,让你求出所有可能操作 的答案和. (1 <= n, m <= 50) 思路:巨难.. ...