北华大学第五届程序设计竞赛春季联赛水题
发布日期:2021-05-07 23:18:07 浏览次数:22 分类:原创文章

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

Powered by:AB_IN 局外人

t=int(input())while t>0:    t-=1    n=int(input())    if n&1:        print("YES")    else:        print("NO")

t=int(input())while t>0:    t-=1    s=input().strip()    for i in s:        if i.islower():            print(i,end="")    print()

#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 int read(){           register int 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;}ll x,y,t,nx,ny;int main(){       using namespace IO;    t=read();    while(t--){           ll ans=0;        x=read();y=read();        if(x==y){               write(x*4);pc('\n');            continue;        }        else{               while(1){               nx=min(x,y);            ny=max(x,y);            if(nx==1)            {   ans+=ny*4;break;}            ny-=nx;            ans+=nx*4;            x=nx;            y=ny;            if(nx==ny)            {   ans+=nx*4;break;}            }        }        write(ans);pc('\n');    }}

DP

  1. dp[i][1]代表这次我选这个数,那么总数就是这个数和上个不选这个数的值相加。
  2. dp[i][0]代表这次我不选这个数,那么这个值就是上一个状态两个值中的最大值。
#include <bits/stdc++.h>typedef long long ll;const ll maxn=1e4;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 int read(){           register int 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;}ll a[maxn],dp[maxn][2],t,n;int main(){       using namespace IO;    t=read();    while(t--)    {           n=read();        for(int i=1;i<=n;i++)            a[i]=read();        dp[1][0]=0;        dp[1][1]=a[1];        for(int i=2;i<=n;i++)        {               dp[i][1]=dp[i-1][0]+a[i];            dp[i][0]=max(dp[i-1][0],dp[i-1][1]);        }        write(max(dp[n][0],dp[n][1]));        pc('\n');    }}

完结。

上一篇:牛客编程语言练习赛第三场
下一篇:Py3 字典基本知识

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年03月29日 09时07分27秒