【BZOJ】4721: [Noip2016]蚯蚓

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4721

先切出来的长的那段不会短于后切出来的长的(短的同样也成立)
所以每次被切的时候把长的扔进一个数组,短的扔进一个数组。这样数组就是有序的了。
然后每次从三个数组头找最大的切就好了。

输出格式:行末无空格,第二行无回车

#include<stdio.h>
#include<algorithm>
#include<iostream>
#define Void inline void
#define cint const int &
#define cbool const bool &
#define N 7100005
using namespace std;

typedef long long ll;

int ha,ta,hb,tb,hc,tc,a[N],b[N],c[N],tm,opt[N],Ta[N],Tb[N],Tc[N],n,m,q,u,v,t,ed,st=1;

inline int cal(cint p)
{
    if (p==1) return ha<ta?a[ha+1]+q*(tm-Ta[ha+1]):-1;
    if (p==2) return hb<tb?b[hb+1]+q*(tm-Tb[hb+1]):-1;
    if (p==3) return hc<tc?c[hc+1]+q*(tm-Tc[hc+1]):-1;
}

Void PlanB(cint k,cbool f)
{
    int g=cal(k),p1=(ll)g*u/v,p2=g-p1;
    if (f) opt[++ed]=g;
    if (p1<p2) swap(p1,p2);
    b[++tb]=p1;Tb[tb]=tm+1;
    c[++tc]=p2;Tc[tc]=tm+1;
}

Void pf(cint k,cbool f){if (f) opt[++ed]=cal(k);}

Void solve(cbool f,cbool op)
{
    int k1=cal(1),k2=cal(2),k3=cal(3);
    if (k2<=k1 && k3<=k1) (op?PlanB(1,f):pf(1,f)),ha++;
    else if (k3<=k2) (op?PlanB(2,f):pf(2,f)),hb++;
    else (op?PlanB(3,f):pf(3,f)),hc++;
    if (f) st=0;
}

Void out()
{
    for (int i=1;i<ed;i++) printf("%d ",opt[i]);
    if (ed) printf("%d",opt[ed]);
    ed=0;st=1;
}

int main()
{
    scanf("%d%d%d%d%d%d",&n,&m,&q,&u,&v,&t);
    for (int i=1;i<=n;i++) scanf("%d",a+i);ta=n;
    sort(a+1,a+n+1,greater<int>());
    for (int i=0;i<m;i++,st++) tm=i,solve(t==st,1);tm=m;out();printf("\n");
    for (int i=1;i<=n+m;i++,st++) solve(t==st,0);out();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值