zoukankan      html  css  js  c++  java
  • 浴谷八连测R4

     1.T14561 逃避

    题解::
    第一题水题,直接模拟就行了。
    代码::
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    template<class T>inline void read(T &x)
    {
        x=0;int f=0;char ch=getchar();
        while(ch<'0'||ch>'9')f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        x=f?-x:x;
        return;
    }
    char s[100100];
    int main()
    {
        gets(s);
        int l=strlen(s);
        bool flag=true;
        for(int i=0;i<l;i++)
        {
            if(s[i]=='.')flag=true;
            else if(flag)
            {
                if(s[i]<='z'&&s[i]>='a')s[i]=s[i]-'a'+'A';
                if(s[i]>='A'&&s[i]<='z')flag=false;
            }
            else if(!flag){
                if(s[i]<='Z'&&s[i]>='A')s[i]=s[i]-'A'+'a';
            }
        }
        printf("%s",s);
        return 0;
    }
    
    

     2.T14562 可耻

    题解::
    要求字典序最小,我们可以每次贪心取出不在最后的最大值和它的下一位,最大值可以用优先队列,求下一位用链表就行了。
    #include<cstdio>
    #include<queue>
    #include<algorithm>
    #define re register
    using namespace std;
    template<class T>inline void read(T &x)
    {
        x=0;char ch=getchar();
        while(ch<'0'||ch>'9')ch=getchar();
        while(ch<='9'&&ch>='0')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        return;
    }
    int a[100100],k[100100],pre[100100],next[100100];
    bool vis[100100];
    priority_queue<int>Q;
    int main()
    {
        int n;
        read(n);
        for(re int i=1;i<=n;i++)
        {
            read(a[i]);
            Q.push(a[i]);
            k[a[i]]=i;
            next[i]=i+1;
            pre[i]=i-1;
        }
        for(re int i=1;i<=n/2;i++)
        {
            while(vis[Q.top()])Q.pop();
            re int x=k[Q.top()],y=next[x];
            if(y==n+1){
                Q.pop();
                while(vis[Q.top()])Q.pop();
                re int X=k[Q.top()],Y=next[X];
                printf("%d %d ",a[X],a[Y]);
                pre[next[Y]]=pre[X];
                next[pre[X]]=next[Y];
                vis[a[X]]=true;vis[a[Y]]=true;
                Q.push(a[x]);
            }
            else {
                printf("%d %d ",a[x],a[y]);
                pre[next[y]]=pre[x];
                next[pre[x]]=next[y];
                vis[a[x]]=true;vis[a[y]]=true;
            }
        }
        return 0;
    }
    
    

    3.T14563 但有用

    题解::先3进制枚举每一行加的,再贪心求出每一列就行了。

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    template<class T>inline void read(T &x)
    {
        x=0;char ch=getchar();
        while(ch<'0'||ch>'9')ch=getchar();
        while(ch<='9'&&ch>='0')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        return;
    }
    int num[20],a[20][20],c[20][3];
    void calc(int x)
    {
        memset(num,0,sizeof(num));
        int t=0;
        while(x)
        {
            num[++t]=x%3;
            x/=3;
        }
    }
    int main()
    {    
        int n,m,sum,ans=0;
        read(n);read(m);
        for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        read(a[i][j]);
        int k=1;
        for(int i=1;i<=n;i++)k*=3;
        for(int o=0;o<k;o++)
        {
            calc(o);memset(c,0,sizeof(c));sum=0;
            for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            if(a[i][j]+num[i]<=12)c[j][(a[i][j]+num[i])%3]++;
            for(int j=1;j<=m;j++)
            sum=sum+max(c[j][0],max(c[j][1],c[j][2]));
            ans=max(sum,ans);
        }
        printf("%d\n",ans);
        return 0;
    }

    总结::

    这套题与之前的题相比较水,前两道题很简单,考试时码的也很快,打完对拍后才过了一个小时,给第三题留的时间多.。继续保持。

  • 相关阅读:
    EF数据库初始化策略及种子数据的添加
    Win10 FaceAPI小demo开发问题汇总
    本地Git服务器的搭建及使用
    JSP利用freemarker生成基于word模板的word文档
    Mvc项目架构分享之项目扩展
    mvc项目架构搭建之UI层的搭建
    mvc项目架构分享系列之架构搭建之Repository和Service
    mvc项目架构分享系列之架构搭建之Infrastructure
    mvc项目架构分享系列之架构搭建初步
    [svc]HTTPS证书生成原理和部署细节
  • 原文地址:https://www.cnblogs.com/jiangtao0508/p/7719818.html
Copyright © 2011-2022 走看看