[2019.10.04] NOIP2019 simulation training title

to sum up

T1 think for too long (1h30min), the idea is entirely correct, but dp understanding itself is not enough time complexity is not right, thought it was wrong did not play.

T2 greedy (are not really simulate it ... probably closer to its essence) directly over, useless half. About 30min before.

T3 10 minutes should be able to get. On the T1 card so completely throw away.

Overall still have to brush questions and more sum up, when the exam to get the first Grab points, some points to bring good, do not spend too long on a question of time.

 

T1.

? ? ? I did not break out how this question. I'm good food.

? ? ? I did not play how thinking is correct. I'm good food.

Sure enough, or their own hands to score points and run.

Code:

#include<bits/stdc++.h>
#define For(i,l,r) for(int i=l;i<=r;i++)
#define DFor(i,r,l) for(int i=r;i>=l;i--)
#define ll long long
#define ri register int
using namespace std;
const int M=666;
ll n,a[M],f[M][M],g[M][M],ans;
bool b[M];
inline ll read(){
    ll f=1,sum=0;
    char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){sum=(sum<<1)+(sum<<3)+(ch^48);ch=getchar();}
    return f*sum;
}
inline void sets(){
    For(i,1,n) g[i][i]=1;
    For(i,1,n-1){
        memset(b,0,sizeof(b));
        b[a[i]]=1;
        For(j,i+1,n){
            if(b[a[j]]) g[i][j]=g[i][j-1];
            else b[a[j]]=1,g[i][j]=g[i][j-1]+1;
        }
    }
}
int main(){
    freopen("merge.in","r",stdin);
    freopen("merge.out","w",stdout);
    n=read();
    For(i,1,n) a[i]=read(),a[n+i]=a[i];
    n<<=1;
    sets();
    DFor(i,n-1,1){
        For(j,i+1,n){
            For(k,i,j-1){
                f[i][j]=max(f[i][j],f[i][k]+f[k+1][j]+g[i][k]*g[k+1][j]);    
            }
        }
    }
    For(i,1,n) ans=max(ans,f[i][i+(n>>1)-1]);
    printf("%lld",ans);
    return 0;
}
View Code

 

T2.

(I ran to get finished part points) 40 points seems a good point to take a special look → (suddenly found) Ci = Ci zero will drown under consideration of zero can not yet, not time complexity count, 80 points is always there, right → (after finished) told to use half over I hung up → (see results) AK up ??

Direct throw Code:

#include<bits/stdc++.h>
#define For(i,l,r) for(int i=l;i<=r;i++)
#define DFor(i,r,l) for(int i=r;i>=l;i--)
#define ll long long
#define ri register int
using namespace std;
const int M=1e5+5;
ll n,l,c[M],ans,wall,ea[M],cnt=1;
bool fb,fc;
struct node{
    ll a,b,u;
}e[M];
inline ll read(){
    ll f=1,sum=0;
    char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){sum=(sum<<1)+(sum<<3)+(ch^48);ch=getchar();}
    return f*sum;
}
inline ll cmpa(node x,node y) {return x.a>y.a;}
inline ll cmpp(node x,node y) {return x.u==y.u?x.a<y.a:x.u>y.u;}
inline ll cmpea(ll x,ll y) {return x>y;}
int main(){
    freopen("climb.in","r",stdin);
    freopen("climb.out","w",stdout);
    n=read(),l=read();
    For(i,1,n){
        e[i].a=read();e[i].b=read();e[i].u=e[i].a-e[i].b;
        ea[i]=e[i].a;
        if(e[i].b) fb=1;
    }
    For(i,1,n){
        c[i]=read();
        if(c[i]) fc=1;
    }
    if(!fb){//no fall
        sort(e+1,e+n+1,cmpa);
        For(i,1,n){
            ans+=e[i].a;
            wall+=c[i];
            if(ans<0){
                printf("-1");
                return 0;
            }
            if(ans>=l){
                printf("%d",i);
                return 0;
            }
            if(ans<=wall){
                printf("-1");
                return 0;
            }
        }
        printf("-1");
        return 0;
    }
    if(!fc){//no wall
        sort(e+1,e+n+1,cmpp);
        sort(ea+1,ea+n+1,cmpea);
        For(i,1,n){
            if(ans<0){
                printf("-1");
                return 0;
            }
            if(ans+ea[1]>=l){
                printf("%d",i);
                return 0;
            }
            ans+=e[i].u;
            if(ea[1]==e[i].a){
                ea[1]=ea[++cnt];
            }
        }
        printf("-1");
        return 0;
    }
    sort(e+1,e+n+1,cmpp);
    sort(ea+1,ea+n+1,cmpea);
    For(i,1,n){
        if(ans+ea[1]>=l){
            printf("%d",i);
            return 0;
        }
        ans+=e[i].u;
        wall+=c[i];
        if(ans<=wall){
            printf("-1");
            return 0;
        }
        if(ans<0){
            printf("-1");
            return 0;
        }
        if(ea[1]==e[i].a){
            ea[1]=ea[++cnt];
        }
    }
    printf("-1");
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/jian-song/p/11622101.html