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

      一开始出了点bug能看见排行榜,于是我看见我半个小时就A掉了前两题,信心场QAQ

      T1字符串题就不说了qwq

    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio> 
    #include<algorithm>
    #define ll long long 
    using namespace std;
    const int maxn=500010,inf=1e9;
    int n,m,x,y,z,tot;
    char c;
    int main()
    {
        int daxie=1;
        while((c=getchar())!=EOF)
        {
            if(('a'<=c&&c<='z')||('A'<=c&&c<='Z'))
            {
                if(daxie)
                {
                    if('a'<=c&&c<='z')putchar(c-'a'+'A');
                    else putchar(c);
                    daxie=0;
                }
                else 
                {
                    if('a'<=c&&c<='z')putchar(c);
                    else putchar(c-'A'+'a');
                }
            }
            else if(c=='.')daxie=1,putchar('.');
            else putchar(' ');
        }
        return 0;
    }
    View Code

      T2直接贪心不断找出最大的数和他的下一个数,用双向链表维护一下前面和后面的数就好了

    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio> 
    #include<algorithm>
    #include<queue>
    #define ll long long 
    using namespace std;
    const int maxn=500010,inf=1e9;
    struct poi{int pos,w;};
    priority_queue<poi>q;
    bool operator<(poi a,poi b){return a.w<b.w;}
    int n,m,x,y,z,tot;
    int nxt[maxn],pre[maxn],a[maxn];
    bool v[maxn];
    void read(int &k)
    {
        int f=1;k=0;char c=getchar();
        while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
        while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
        k*=f;
    }
    void del(int x)
    {
        nxt[pre[x]]=nxt[nxt[x]];
        pre[nxt[nxt[x]]]=pre[x];
        pre[x]=nxt[x]=pre[nxt[x]]=nxt[nxt[x]]=0;
    }
    int main()
    {
        read(n);
        for(int i=1;i<=n;i++)read(a[i]),pre[i]=i-1,nxt[i]=i+1,q.push((poi){i,a[i]});
        for(int i=1;i<=n>>1;i++)
        {
            poi t=q.top();q.pop();
            while(v[t.pos]||nxt[t.pos]>n)t=q.top(),q.pop();
            printf("%d %d ",t.w,a[nxt[t.pos]]);
            v[nxt[t.pos]]=1;del(t.pos);
        }
        return 0;
    }
    View Code

      T3可以发现每行每列最多加两次,因为每隔2个数就有一个稳数...于是3^n枚举列的状态,算出每一行不加,加一个,加两个哪个优,每一行互不影响,于是每一行贪心地选一个最大的就好了

    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio> 
    #include<algorithm>
    #define ll long long 
    using namespace std;
    const int maxn=20,inf=1e9;
    int n,m,x,y,z,ans;
    int mp[maxn][maxn],mi[maxn];
    void read(int &k)
    {
        int f=1;k=0;char c=getchar();
        while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
        while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
        k*=f;
    }
    int main()
    {
        read(n);read(m);
        for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)read(mp[i][j]);
        mi[0]=1;for(int i=1;i<=max(n,m);i++)mi[i]=mi[i-1]*3;
        for(int s=0;s<=mi[m];s++)
        {
            int now=0;
            for(int i=1;i<=n;i++)
            {
                int tmp1,tmp2,tmp3;tmp1=tmp2=tmp3=0;
                for(int j=1;j<=m;j++)
                if(s/mi[j-1]%3==1)
                {
                    tmp1+=(mp[i][j]==2||mp[i][j]==5||mp[i][j]==8||mp[i][j]==11);
                    tmp2+=(mp[i][j]==1||mp[i][j]==4||mp[i][j]==7||mp[i][j]==10);
                    tmp3+=(mp[i][j]==0||mp[i][j]==3||mp[i][j]==6||mp[i][j]==9);
                }
                else if(s/mi[j-1]%3==0)
                {
                    tmp1+=(mp[i][j]==3||mp[i][j]==6||mp[i][j]==9||mp[i][j]==12);
                    tmp2+=(mp[i][j]==2||mp[i][j]==5||mp[i][j]==8||mp[i][j]==11);
                    tmp3+=(mp[i][j]==1||mp[i][j]==4||mp[i][j]==7||mp[i][j]==10);
                }
                else if(s/mi[j-1]%3==2)
                {
                    tmp1+=(mp[i][j]==1||mp[i][j]==4||mp[i][j]==7||mp[i][j]==10);
                    tmp2+=(mp[i][j]==0||mp[i][j]==3||mp[i][j]==6||mp[i][j]==9);
                    tmp3+=(mp[i][j]==-1||mp[i][j]==2||mp[i][j]==5||mp[i][j]==8);
                }
                now+=max(tmp1,max(tmp2,tmp3));
            }
            ans=max(ans,now);
        }
        printf("%d
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    HDU 1495 非常可乐
    ja
    Codeforces Good Bye 2016 E. New Year and Old Subsequence
    The 2019 Asia Nanchang First Round Online Programming Contest
    Educational Codeforces Round 72 (Rated for Div. 2)
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)
    AtCoder Regular Contest 102
    AtCoder Regular Contest 103
    POJ1741 Tree(点分治)
    洛谷P2634 [国家集训队]聪聪可可(点分治)
  • 原文地址:https://www.cnblogs.com/Sakits/p/7709879.html
Copyright © 2011-2022 走看看