P2827 [NOIP2016 提高组] 蚯蚓

#include <bits/stdc++.h>
using namespace std;
using PII = pair<int,int >;
using ll  = long long;
using VI = vector<int>;
using namespace std;

//a b
//c d
ll n,m,q,u,v,t;
priority_queue<long long> pq;
VI a,r;
int main(){
    //priority_queue<int> pq;
    cin>>n>>m>>q>>u>>v>>t;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;;
        pq.push(x);
    }
  
    //每个没被切的蚯蚓会增长q ,  不妨将新加入的蚯蚓再砍了q
    //维护相对大小,同时维护这个数组会被加几个q
    ll add = 0;
    for(int i=1;i<=m;i++){
        auto x = pq.top() + add;
        pq.pop();
        if(i % t == 0){
            cout<<x<<" ";
        }
        int px = x * u / v;
        int ps = x - px;
        px -= add, ps -= add;
        px -= q, ps -= q;
        pq.push(px) , pq.push(ps);
        add += q;
    }
    ll time = 1;
    cout<<"\n";
    while (pq.size()){
        auto x = pq.top() + add;
        pq.pop();
        if(time % t == 0){
            cout<<x<<" ";
        }
        time ++;
    }


}

非正解,但是里面的思想还是很重要的,就是每个数都加q,不妨就把新的蚯蚓减去q, 用add来维护加了多少次

——————————————————————————————————————————

#include <bits/stdc++.h>
using namespace std;
using PII = pair<int,int >;
using ll  = long long;
using VI = vector<int>;
using namespace std;

//a b
//c d
ll n,m,q,u,v,t;
priority_queue<long long> pq;
VI tmp;
queue<ll> a,b,c;
bool cmp(ll x ,ll y){
    return x > y;
}
ll getMax(){
    ll res = -1e18;
    if(a.size()) res = max(res,a.front());
    if(c.size()) res = max(res,b.front());
    if(b.size()) res = max(res,c.front());

    if(a.size() && res == a.front()) a.pop();
    else if( b.size() && res == b.front()) b.pop();
    else if( c.size() && res == c.front() ) c.pop();

    return res;
}




int main(){
    //priority_queue<int> pq;
    cin>>n>>m>>q>>u>>v>>t;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        tmp.push_back(x);
    }
    sort(tmp.begin(),tmp.end(),cmp);
    for(auto x : tmp) a.push(x);

    ll add = 0;
    for(int i=1;i<=m;i++){
        auto x = getMax() + add;
        if(i % t == 0){
            cout<<x<<" ";
        }

        ll px = x * u / v;
        ll ps = x - px;
        if(ps < ps) swap(ps,px);
        px -= add , ps -= add;
        px -= q , ps -= q;
        b.push(px) , c.push(ps);
        add += q;
    }


    cout<<"\n";
    //每个没被切的蚯蚓会增长q ,  不妨将新加入的蚯蚓再砍了q
    //维护相对大小,同时维护这个数组会被加几个q
    while(a.size()) pq.push(a.front()),a.pop();
    while(b.size()) pq.push(b.front()),b.pop();
    while(c.size()) pq.push(c.front()),c.pop();

    int time = 1;
    while(pq.size()){
        if(time % t == 0){
            cout<<pq.top() + add<<" ";
        }
        pq.pop();
        time ++;
    }




}

 正解需要能观察出一定的性质,

如果蚯蚓 a 比 b  先被切,那么他的子段就一定比b先切

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值