P4241【NOIP2016 DAY2】蚯蚓
2017-09-21 16:43
375 查看
http://oi.nks.edu.cn/zh/Problem/Details?id=4241
设当前时间两蚯蚓长度x,y且满足x>y,
所以 2秒后 x新长度为x*p+q
y新长度为(y+q)*p=y*p+q*p
因为q<0
又所以其新增的蚯蚓长度满足单调递增
所以考虑用三个单调队列来维护
题解
堆暴力60分设当前时间两蚯蚓长度x,y且满足x>y,
所以 2秒后 x新长度为x*p+q
y新长度为(y+q)*p=y*p+q*p
因为q<0
又所以其新增的蚯蚓长度满足单调递增
所以考虑用三个单调队列来维护
代码
#include<stdio.h> #include<algorithm> #include<queue> #include<cmath> #include<cstdio> #include<iostream> using namespace std; #define maxn1 100005 #define maxn2 7200000 #define int long long int n,m,q,u,v,t; int a[maxn1]; struct node{ int x,t; }; bool cmp(int x,int y){ return x>y; } deque<node>b; deque<node>c; int p1,q1; int st=1; void work(int x,int now) { node t1,t2; if(now%t==0){ printf("%d ",x); } p1=x*u/v; q1=x-p1; t1.x=p1;t1.t=now; t2.x=q1;t2.t=now; b.push_back(t1); c.push_back(t2); } main() { int i,j,k; scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&q,&u,&v,&t); for(i=1;i<=n;i++) scanf("%lld",&a[i]); sort(a+1,a+1+n,cmp); if(m!=0) work(a[st++],1); for(i=2;i<=m;i++){ int af=-1,bf=-1,cf=-1; if(st<=n) af=a[st]+(i-1)*q; if(b.size()) bf=b.front().x+(i-b.front().t-1)*q; if(c.size()) cf=c.front().x+(i-c.front().t-1)*q; if(af>=bf&&af>=cf){ st++; work(af,i); } else if(bf>=af&&bf>=cf){ b.pop_front(); work(bf,i); } else if(cf>=af&&cf>=bf){ c.pop_front(); work(cf,i); } } printf("\n"); for(i=1;i<=m+n;i++){ int maxx=0; int af=-1,bf=-1,cf=-1; if(st<=n) af=a[st]+m*q; if(!b.empty()) bf=b.front().x+(m-b.front().t)*q; if(!c.empty()) cf=c.front().x+(m-c.front().t)*q; if(af>=bf&&af>=cf){ st++; maxx=af; } else if(bf>=af&&bf>=cf){ b.pop_front(); maxx=bf; } else if(cf>=af&&cf>=bf){ c.pop_front(); maxx=cf; } if(i%t==0) printf("%lld ",maxx); } }
相关文章推荐
- 2016 noip day2蚯蚓总结
- NOIP2016 day2 t2蚯蚓
- UOJ264 NOIP2016 day2 T2 蚯蚓(队列)
- 蚯蚓 NOIP2016 提高组 Day2 T2
- [luogu-2877]noip2016-day2-T2 蚯蚓 题解
- noip2016 Day2 T2:蚯蚓 (归并)
- 【NOIP 2016 day2 T1 T2】组合数问题,蚯蚓——题解
- NOIP 2016提高组 Day2 蚯蚓
- 【NOIP2016提高组day2】蚯蚓
- NSFZOJ #1066. 【NOIP2016】蚯蚓
- NOIP2016 Day2 T2 天天爱跑步(树上差分)
- [noip2016]蚯蚓 题解
- NOIP 2016 提高组 Day2 组合数问题
- bzoj 4721: [Noip2016]蚯蚓 单调队列
- bzoj4721 [Noip2016]蚯蚓(模拟)
- NOIP 2016 Day2 T3 愤怒的小鸟
- BZOJ4721 [Noip2016]蚯蚓
- [NOIP2016]蚯蚓 D2 T2 队列
- NOIP 2016 Day2 T3 愤怒的小鸟
- UOJ 264 NOIP2016 DAY2 T2 浅谈队列单调性及辅助队列时间戳