Loading

NOIP 2016 D2T2 蚯蚓](思维)

NOIP 2016 D2T2 蚯蚓

题目大意

本题中,我们将用符号 \(\lfloor c \rfloor⌊c⌋\) 表示对 \(c\) 向下取整,例如:\(\lfloor 3.0 \rfloor = \lfloor 3.1 \rfloor = \lfloor 3.9 \rfloor = 3⌊3.0⌋=⌊3.1⌋=⌊3.9⌋=3\)

蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭蚯蚓。

蛐蛐国里现在共有 n 只蚯蚓(n 为正整数)。每只蚯蚓拥有长度,我们设第 i 只蚯蚓的长度为 \(a_i(i=1,2,\dots,n_i=1,2,…,n)\),并保证所有的长度都是非负整数(即:可能存在长度为 0 的蚯蚓)。

每一秒,神刀手会在所有的蚯蚓中,准确地找到最长的那一只(如有多个则任选一个)将其切成两半。神刀手切开蚯蚓的位置由常数 p(是满足 0 < p < 10 < p < 1 的有理数)决定,设这只蚯蚓长度为 x,神刀手会将其切成两只长度分别为$ \lfloor px $ 和 $x - \lfloor px $的蚯蚓。特殊地,如果这两个数的其中一个等于 0,则这个长度为 0 的蚯蚓也会被保留。此外,除了刚刚产生的两只新蚯蚓,其余蚯蚓的长度都会增加 q(是一个非负整常数)。

蛐蛐国王知道这样不是长久之计,因为蚯蚓不仅会越来越多,还会越来越长。蛐蛐国王决定求助于一位有着洪荒之力的神秘人物,但是救兵还需要 m 秒才能到来……(m 为非负整数)

蛐蛐国王希望知道这 m 秒内的战况。具体来说,他希望知道:

  • m 秒内,每一秒被切断的蚯蚓被切断前的长度(有 m 个数);
  • m 秒后,所有蚯蚓的长度(有 n + m 个数)。
    蛐蛐国王当然知道怎么做啦!但是他想考考你……

Solution

给我T飞了
刚开始没用想到单调性这个东西
只是单纯的去模拟了操作并且取最优解
那么那里来的单调性呢
先被切掉的蚯蚓分成的蚯蚓一定比后切掉的蚯蚓分成的蚯蚓大
如何证明呢

我们假设有两条蚯蚓\(x,y(x>y)\)
当前时刻\(x\)断裂为\(x_1, x_2\)
过了不知道t秒后\(y\)有丝分裂成了\(y_1,y_2\)
\(a_1\)的长度为\(a_1+t = p*l_a + t\)
同理可以得到\(a_2\)的长度为\(a_2 + t = (1 - p) * l_a + t\)
显然\(a_1>b_1\)\(a_2 > b_2\)
推广到\(a>b>c>……>n\)的话就得到了我们要的结论
所以说数据是具有单调性的

80分优先队列

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
#define int long long
using namespace std;
const int maxn=10005;

priority_queue<int> que;

inline int read(){
    int x=0,w=1;
    char ch=getchar();
    for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
    for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*w;
}

int n,m,q,u,v,t;
double p;
int length;

int l1,l2;
int sigma;

signed main(){
    n=read(),m=read(),q=read();
    u=read(),v=read(),t=read();
    p=(double)u/(double)v;
    for(int i=1;i<=n;i++){
        length=read();
        que.push(length);
    }
    for(int i=1;i<=m;i++){
        l1=0,l2=0;
        int temp;
        temp=que.top();
        que.pop();
        temp+=sigma;
        l1=floor(p*(double)temp);
        l2=temp-l1;
        l1-=sigma,l2-=sigma;
        l1-=q,l2-=q;
        que.push(l1),que.push(l2);
        if(i%t==0) cout<<temp<<' ';
        sigma+=q;
    }
    cout<<'\n';
    for(int i=1;que.size();++i){
        if(i%t==0)
            cout<<que.top()+sigma<<" ";
        que.pop();
    }
    cout<<'\n';
    return 0;
}

明明应该100可是还在T的代码……

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#define N 7000005
using namespace std;

inline bool cmp(const int &a,const int &b){
    return a>b;
}

queue<int>ans;
int cut1[N],now[N],cut2[N];
int n,m,q,u,v,t;
int sigma;
double p;
int h,h1,h2;
int t0,t1,t2;

int main(){
    scanf("%d%d%d%d%d%d",&n,&m,&q,&u,&v,&t);
    p=(double)u/v;int tmp;
    for(t0=1;t0<=n;++t0)
        scanf("%d",&now[t0]);
    --t0;t1=t2=0;h=h1=h2=1;
    sort(now+1,now+t0+1,cmp);
    int top;
    for(int i=1;i<=m;++i){
        if(h>t0){if(cut1[h1]>cut2[h2])top=cut1[h1++];else top=cut2[h2++];}
        else if(now[h]>=cut1[h1]&&now[h]>=cut2[h2])
            top=now[h],++h;
        else if(cut1[h1]>=cut2[h2]&&now[h]<=cut1[h1])
            top=cut1[h1],++h1;
        else top=cut2[h2],++h2;
        top+=sigma;
        int a1=floor(p*(double)top),a2=top-a1;
        sigma+=q;
        a1-=sigma,a2-=sigma;
        cut1[++t1]=a1,cut2[++t2]=a2;
        if(i%t==0)printf("%d ",top);
    }
    putchar('\n');
    for(int i=h;i<=t0;++i)ans.push(now[i]);
    for(int i=h1;i<=t1;++i)ans.push(cut1[i]);
    for(int i=h2;i<=t2;++i)ans.push(cut2[i]);
    for(int i=1;ans.size();++i){
        if(i%t==0)printf("%d ",ans.top()+sigma);
        ans.pop();
    }
    return 0;
}

就nm离谱
这啥情况呢
听说读入之后排序就能A?
一样的复杂度改了就能A?
能信?
它就这么发生了……
(源于YouXam,感谢YouXam指正)


#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
long long INF = 0x3f3f3f3f3f3f3f3f;
int n, m, q, u, v, t, delta = 0, w, a[100005], ai = 1;
queue<int> q1, q2;
inline bool cmp(int a, int b) { return a > b; }
int main() {
    scanf("%d%d%d%d%d%d", &n, &m, &q, &u, &v, &t);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    sort(a + 1, a + n + 1, cmp);
    for (int i = 1; i <= m; i++) {
        long long maxx = -INF;
        if (ai <= n && maxx < a[ai]) maxx = a[ai], w = 0;
        if (q1.size() && maxx < q1.front())
            maxx = (long long)q1.front(), w = 1;
        if (q2.size() && maxx < q2.front()) 
            maxx = (long long)q2.front(), w = 2;
        if(w == 1) q1.pop();
        else if (w == 2) q2.pop();
        else ai++;
        maxx += delta;
        q1.push(maxx * u / v - delta - q);
        q2.push(maxx - maxx * u / v - delta - q);
        delta += q;
        if (i % t == 0) printf("%lld ", maxx);
    }
    printf("\n");
    for (int i = 1; i <= n + m; i++) {
        long long maxx = -INF;
        if (ai <= n && maxx < a[ai]) maxx = a[ai], w = 0;
        if (q1.size() && maxx < q1.front()) 
            maxx = (long long) q1.front(), w = 1;
        if (q2.size() && maxx < q2.front()) 
            maxx = (long long) q2.front(), w = 2;
        if(w == 1) q1.pop();
        else if (w == 2) q2.pop();
        else ai++;
        if (i % t == 0) printf("%lld ", maxx + delta);
    }
    return 0;
}
posted @ 2020-04-17 13:51  Gary_818  阅读(133)  评论(0编辑  收藏  举报