每日一题 day32 打卡

Analysis

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

我们先把原序列排序,因为不管怎么切,先被切的蚯蚓分成的两部分一定比后切的蚯蚓分成的两部分大(较大的部分和较大的部分比较,较小的部分和较小的部分比较),所以我们可以省去每一秒增加每只蚯蚓的长度这个操作,转换成在查询砍那只蚯蚓时,把增加的长度算到蚯蚓的总长度上。

寻找每次砍哪一只蚯蚓就是在队列1、队列2、队列3的队头找一个算上增加的长度最大的蚯蚓,之后把他出队,切开的两部分分别进入队2、队3。

对于增量的计算我们可以按照蚯蚓在队列中的标号,因为队列1中的蚯蚓直到被切是一直处于一种增长状态,所以直接加上(当前时间-1) \* Q就可以了,而对于队列2和队列3的蚯蚓,他的增长是从被切掉那一刻的下一秒开始的,所以他的增长量则是(当前时间-1-被切割的时间)\*Q

统计答案的时候把三个队列合并,排序输出就可以了。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define maxm 7000000+10
#define R register
using namespace std;
inline int read()
{
int x=;
bool f=;
char c=getchar();
for(; !isdigit(c); c=getchar()) if(c=='-') f=;
for(; isdigit(c); c=getchar()) x=(x<<)+(x<<)+c-'';
if(f) return x;
return -x;
}
inline void write(int x)
{
if(x<){putchar('-');x=-x;}
if(x>)write(x/);
putchar(x%+'');
}
int n,m,q,u,v,t,sum;
double p;
int fir[maxm],sec[maxm],thi[maxm];
int head1,head2,head3,tail1,tail2,tail3;
priority_queue<int> que;
inline bool cmp(int x,int y){return x>y;}
inline int min_three(int x,int y,int z){return min(x,min(y,z));}
inline int max_three(int x,int y,int z){return max(x,max(y,z));}
int main()
{
n=read();m=read();q=read();u=read();v=read();t=read();
for(R int i=;i<=n;i++) fir[i]=read();
p=(double)u/v;
sort(fir+,fir+n+,cmp);
tail1=n;
head1=head2=head3=;
for(R int i=;i<=m;i++)
{
int top=;
if(head1>tail1)
{
if(sec[head2]>=thi[head3]) top=sec[head2],head2++;
else if(sec[head2]<thi[head3]) top=thi[head3],head3++;
}
else if(fir[head1]>=sec[head2]&&fir[head1]>=thi[head3]) top=fir[head1],head1++;
else if(sec[head2]>=fir[head1]&&sec[head2]>=thi[head3]) top=sec[head2],head2++;
else if(thi[head3]>=fir[head1]&&thi[head3]>=sec[head2]) top=thi[head3],head3++;
top+=sum;
int a=floor(p*(double)top);
int b=top-a;
a-=q;b-=q;
a-=sum;b-=sum;
sec[++tail2]=a;
thi[++tail3]=b;
if(i%t==)
{
write(top);
putchar(' ');
}
sum+=q;
}
putchar('\n');
for(R int i=min_three(head1,head2,head3);i<=max_three(tail1,tail2,tail3);i++)
{
if(i>=head1&&i<=tail1) que.push(fir[i]);
if(i>=head2&&i<=tail2) que.push(sec[i]);
if(i>=head3&&i<=tail3) que.push(thi[i]);
}
int vol=que.size();
for(R int i=;i<=vol;i++)
{
if(i%t==)
{
write(que.top()+sum);
putchar(' ');
}
que.pop();
}
return ;
}

请各位大佬斧正(反正我不认识斧正是什么意思)

最新文章

  1. 设计模式--观察者模式初探和java Observable模式
  2. hibernate三种状态
  3. centos7 tomcat service 自启动
  4. python学习之——pip的安装与使用
  5. 添加Labels的两种方法
  6. [译]git rebase
  7. SpringMVC核心——视图渲染(包含视图解析)问题
  8. Linux 千万不要执行的10个命令
  9. keilkill.bat
  10. 使用Sql按日期条件查询
  11. Css3 常见鼠标滑过效果集合
  12. IIS ApplicationPoolIdentity(配置IIS讀寫網站文件)
  13. Linux IPC实践(11) --System V信号量(1)
  14. ubuntu18.04搭建hive
  15. python面向对象基本概念(OOP)
  16. java.io.ByteArrayOutputStream 源码分析
  17. vmp3.0.9全保护拆分解析
  18. MySQL无法存储Emoji表情问题
  19. Java NIO使用及原理分析 (一)(转)
  20. hdu2112HDU Today(floyd+map数组对字符串的应用)

热门文章

  1. 用Python实现扑克牌面试题思路
  2. Django连接多个数据库并实现读写分离
  3. Scala 函数入门之默认参数和带名参数
  4. 少儿编程|Scratch编程教程系列合集,总有一款适合你
  5. Computational biological hypothesis generation using &quot;-omics&quot; data
  6. python3.7 64位中安装pygame1.9.3
  7. requests模块 简单使用
  8. js实现frame框架部分页面的刷新
  9. css设置图片百分比显示,最简洁的代码
  10. 本地ssh快速登录