您的位置:首页 > 其它

P4241【NOIP2016 DAY2】蚯蚓

2017-09-21 16:43 375 查看
http://oi.nks.edu.cn/zh/Problem/Details?id=4241

题解

堆暴力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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: