牛客算法周周练11水题
发布日期:2021-05-07 23:18:11 浏览次数:25 分类:原创文章

本文共 5278 字,大约阅读时间需要 17 分钟。

Powered by:AB_IN 局外人

第一次练习赛AK。

纯模拟,没什么好说的。

#include <bits/stdc++.h>#pragma GCC optimize(2)#pragma GCC optimize(3)typedef unsigned long long ll;const ll maxn=1e6;using namespace std;namespace IO{       char ibuf[1<<21],*ip=ibuf,*ip_=ibuf;    char obuf[1<<21],*op=obuf,*op_=obuf+(1<<21);    inline char gc(){           if(ip!=ip_)return *ip++;        ip=ibuf;ip_=ip+fread(ibuf,1,1<<21,stdin);        return ip==ip_?EOF:*ip++;    }    inline void pc(char c){           if(op==op_)fwrite(obuf,1,1<<21,stdout),op=obuf;        *op++=c;    }    inline ll read(){           register ll x=0,ch=gc(),w=1;        for(;ch<'0'||ch>'9';ch=gc())if(ch=='-')w=-1;        for(;ch>='0'&&ch<='9';ch=gc())x=x*10+ch-48;        return w*x;    }    template<class I>    inline void write(I x){           if(x<0)pc('-'),x=-x;        if(x>9)write(x/10);pc(x%10+'0');    }    class flusher_{       public:        ~flusher_(){   if(op!=obuf)fwrite(obuf,1,op-obuf,stdout);}    }IO_flusher;}using namespace IO;ll n,t,a,b,p[maxn],q[maxn],sum1,sum2,ans1,ans2;int main(){       n=read();t=read();a=read();b=read();sum1=sum2=t;    for(int i=1;i<=n;i++) p[i]=read();//时间    for(int i=1;i<=n;i++) q[i]=read();//难度    for(int i=1;i<=n;i++) {           if(q[i]<a&&sum1>=p[i])sum1-=p[i],ans1++;        if(q[i]<b&&sum2>=p[i])sum2-=p[i],ans2++;        else if(q[i]>=b&&sum2>=2*p[i])sum2-=2*p[i],ans2++;    }    write(ans1);pc(32);write(ans2);    return 0;}

感觉大佬们好像是被题面吓到了。。其实就是单纯的模拟。
差点超时,不是最佳解。

#include <bits/stdc++.h>#pragma GCC optimize(2)#pragma GCC optimize(3)typedef unsigned long long ll;const ll maxn=1e6;using namespace std;namespace IO{       char ibuf[1<<21],*ip=ibuf,*ip_=ibuf;    char obuf[1<<21],*op=obuf,*op_=obuf+(1<<21);    inline char gc(){           if(ip!=ip_)return *ip++;        ip=ibuf;ip_=ip+fread(ibuf,1,1<<21,stdin);        return ip==ip_?EOF:*ip++;    }    inline void pc(char c){           if(op==op_)fwrite(obuf,1,1<<21,stdout),op=obuf;        *op++=c;    }    inline ll read(){           register ll x=0,ch=gc(),w=1;        for(;ch<'0'||ch>'9';ch=gc())if(ch=='-')w=-1;        for(;ch>='0'&&ch<='9';ch=gc())x=x*10+ch-48;        return w*x;    }    template<class I>    inline void write(I x){           if(x<0)pc('-'),x=-x;        if(x>9)write(x/10);pc(x%10+'0');    }    class flusher_{       public:        ~flusher_(){   if(op!=obuf)fwrite(obuf,1,op-obuf,stdout);}    }IO_flusher;}using namespace IO;ll n,t,a[maxn],op1,l,r,k,sum;int main(){       n=read();t=read();    for(ll i=1;i<=n;i++) a[i]=read();    while(t--){           op1=read();sum=0;        if(op1==1){               l=read();r=read();            for(ll i=l;i<=r;i++) sum+=a[i];            write(sum);pc('\n');        }        else{               l=read();r=read();k=read();            for(ll i=l;i<=r;i++) a[i]^=k;        }    }}

正解是dfs+贪心。下面是菜鸡的偷鸡做法。
cin cout不能与IO的同用。

#include <bits/stdc++.h>#pragma GCC optimize(2)#pragma GCC optimize(3)typedef unsigned long long ll;const ll maxn=1e3+10;using namespace std;namespace IO{       char ibuf[1<<21],*ip=ibuf,*ip_=ibuf;    char obuf[1<<21],*op=obuf,*op_=obuf+(1<<21);    inline char gc(){           if(ip!=ip_)return *ip++;        ip=ibuf;ip_=ip+fread(ibuf,1,1<<21,stdin);        return ip==ip_?EOF:*ip++;    }    inline void pc(char c){           if(op==op_)fwrite(obuf,1,1<<21,stdout),op=obuf;        *op++=c;    }    inline ll read(){           register ll x=0,ch=gc(),w=1;        for(;ch<'0'||ch>'9';ch=gc())if(ch=='-')w=-1;        for(;ch>='0'&&ch<='9';ch=gc())x=x*10+ch-48;        return w*x;    }    template<class I>    inline void write(I x){           if(x<0)pc('-'),x=-x;        if(x>9)write(x/10);pc(x%10+'0');    }    class flusher_{       public:        ~flusher_(){   if(op!=obuf)fwrite(obuf,1,op-obuf,stdout);}    }IO_flusher;}//using namespace IO;char a[maxn][maxn];int t,n,m;int main(){       scanf("%d",&t);    while(t--){           scanf("%d%d",&n,&m);        //n=read();m=read();        for(int i=1;i<=n;i++){               cin>>a[i]+1;        }        if(a[1][1]=='R') puts("dreagonm");        else if(a[1][1]=='G') puts("fengxunling");        else puts("BLUESKY007");    }}

经典差分题,没啥好说的。。

#include <bits/stdc++.h>#pragma GCC optimize(2)#pragma GCC optimize(3)typedef  long long ll;const ll maxn=1e6;using namespace std;namespace IO{       char ibuf[1<<21],*ip=ibuf,*ip_=ibuf;    char obuf[1<<21],*op=obuf,*op_=obuf+(1<<21);    inline char gc(){           if(ip!=ip_)return *ip++;        ip=ibuf;ip_=ip+fread(ibuf,1,1<<21,stdin);        return ip==ip_?EOF:*ip++;    }    inline void pc(char c){           if(op==op_)fwrite(obuf,1,1<<21,stdout),op=obuf;        *op++=c;    }    inline ll read(){           register ll x=0,ch=gc(),w=1;        for(;ch<'0'||ch>'9';ch=gc())if(ch=='-')w=-1;        for(;ch>='0'&&ch<='9';ch=gc())x=x*10+ch-48;        return w*x;    }    template<class I>    inline void write(I x){           if(x<0)pc('-'),x=-x;        if(x>9)write(x/10);pc(x%10+'0');    }    class flusher_{       public:        ~flusher_(){   if(op!=obuf)fwrite(obuf,1,op-obuf,stdout);}    }IO_flusher;}using namespace IO;ll n,a[maxn],b[maxn],ans1,ans2;int main(){       n=read();    for(int i=1;i<=n;i++){           a[i]=read();        b[i]=a[i]-a[i-1];        if(b[i]>0) ans1+=b[i];        else ans2-=b[i];    }    write(max(ans1,ans2));    pc('\n');}

完结。

上一篇:WARNING: pip is being invoked by an old script wrapper.
下一篇:哈尔滨理工大学软件与微电子学院程序设计竞赛水题

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年03月31日 02时05分12秒