洛谷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表示每一次被切的蚯蚓被分开的较长的那一部 ...
随机推荐
- sql语句学习(NOT EXISTS 和 NOT IN )
NOT EXISTS SELECT a.*FROM t_user aWHERE a.id_card LIKE '%3203821995100%'AND NOT EXISTS ( SELECT id F ...
- cnblogs正式启用
额,因为最近发现CSDN越来越过分了...现在连数学公式都显示错字体了--于是决定把博客搬至cnblogs. Markdown 测试 \(\frac{-b\pm \sqrt{b^2-4ac}}{2a} ...
- 痛苦的Windows下的temp目录
2007不能运行了,错误: [MSBuild Error] “DCC”任务意外失败. System.Configuration.ConfigurationErrorsException: 配置系统未能 ...
- 【codeforces 793A】Oleg and shares
[题目链接]:http://codeforces.com/contest/793/problem/A [题意] 每次你可以对1..n中的任意一个数字进行减少k操作; 问你最后可不可能所有的数字都变成一 ...
- Spring MVC学习总结(2)——Spring MVC常用注解说明
使用Spring MVC的注解及其用法和其它相关知识来实现控制器功能. 02 之前在使用Struts2实现MVC的注解时,是借助struts2-convention这个插件,如今我们使 ...
- magento 的一些关于addFieldToFilter的查询
1,匹配country_id的首字母,查询国家,返回数组 //查询国家数据集 $countryCollection=Mage::getResourceModel('directory/country_ ...
- root用户不能改动iptables
需求:因为防火墙做了IP和port限制,如今须要加入一条规则使之能够訪问指定的IP和port. vi /etc/sysconfig/iptables, 加入完毕后,wq保存,提示文件仅仅读无法保存.! ...
- 使用 AFNetworking的时候,怎样管理 session ID
问: As the title implies, I am using AFNetworking in an iOS project in which the application talks to ...
- Selenium webdriver-UI Element定位
转:http://blog.csdn.net/jillliang/article/details/8206402 1.创建Fixfox web driver实例 WebDriver driver = ...
- Element UI Form 每行显示多列,即多个 el-form-item
Element UI Form组件使用问题. 每个 el-form-item 都会独占一行. 对于输入项很多的管理app, 能否在每个form中, 每行显示 2 个或者多个 el-form-item ...