2016 noip 蚯蚓(earthworm)模板

地址在这
这道题一开始我没有附初值,否则有负的情况。
longlong超时。。
数组开小 。。
最后虽然过了,但时间总是卡到1s,非常令人不解。
以后做题要仔细,不要忘记一些最基本的错误。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,q,t;
int u,v;
int a[9999999];
int b[9999999];
int h1=1,h2=2,h3=2;
int c[9999999];
int comp(const int &a,const int &b)
{
    if(a>b) return 1;
    else return 0;
}

int main()
{

   // freopen("earthworm.in","r",stdin);
   //    freopen("earthworm.out","w",stdout);
    scanf("%d%d%d%d%d%d",&n,&m,&q,&u,&v,&t);
    memset(a,128,sizeof(a));
    memset(b,128,sizeof(b));
    memset(c,128,sizeof(c));
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1,comp);
    for(int i=1;i<=m;i++)
    {
        long long x=max(a[h1],max(b[h2],c[h3]));
        int y;
        if(a[h1]==x) h1++;
        else if(b[h2]==x) h2++;
        else  h3++; 
        x=x+q*(i-1); 
        if(i%t==0)printf("%lld ",x);
        b[i+1]=x*u/v-q*i;
        c[i+1]=x-x*u/v-q*i;
    }
    printf("
");
    for(int i=1;i<=n+m;i++)
    {
        long long x=max(a[h1],max(b[h2],c[h3]));
        if(a[h1]==x) h1++;    
        else if(b[h2]==x) h2++;
        else  h3++;
        if(i%t==0) printf("%lld ",x+q*m); 
    }


   // fclose(stdin);
   // fclose(stdout);
    return 0;
}
原文地址:https://www.cnblogs.com/wspl98765/p/6819910.html