BC 81

1、Machine


分析:3進制,水題


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

char str[4]={'R','G','B'};

int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        int m;
        long long n;
        scanf("%d%lld",&m,&n);
        int color[35];
        memset(color,0,sizeof(color));
        int g=m;
        while (n && g)//g=0 мЭ╪геп╤о
        {
            color[g]=n%3;
            n/=3;
            g--;
        }
        for (int i=1;i<=m;i++)
            printf("%c",str[color[i]]);
        puts("");
    }
    return 0;
}


2、Matrix


分析:設定兩個數組分別存儲行和列,如果交換,只需交換兩個數組的值,水題


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;


int main()
{
    int t;
    scanf("%d",&t);
    while (t-- > 0)
    {
        int cow[1005],row[1005];
        int juzhen[1005][1005];
        int n,m;
        int q;
        scanf("%d%d%d",&n,&m,&q);
        for (int i=1;i<=n;i++)
            row[i]=i;
        for (int i=1;i<=m;i++)
            cow[i]=i;
        for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            scanf("%d",&juzhen[i][j]);
        while (q--)
        {
            int a,b,c,g;
            scanf("%d%d%d",&a,&b,&c);
            switch(a)
            {
                case 1:
                    g=row[b];
                    row[b]=row[c];
                    row[c]=g;
                    break;
                case 2:
                    g=cow[b];
                    cow[b]=cow[c];
                    cow[c]=g;
                    break;
                case 3:for (int i=1;i<=m;i++)
                            juzhen[row[b]][i]+=c;
                        break;
                case 4:for (int i=1;i<=n;i++)
                            juzhen[i][cow[b]]+=c;
                        break;
            }
        }
        for (int i=1;i<=n;i++)
        {
            for (int j=1;j<=m-1;j++)
                printf("%d ",juzhen[row[i]][cow[j]]);
            printf("%d\n",juzhen[row[i]][cow[m]]);
        }
    }
    return 0;
}


3、String


分析:尺取法,具體問度娘吧,具體我也解釋不清楚


#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn=1e6+10;
int ch[30];
char str[maxn];

int main()
{
    int t;
    int k;
    scanf("%d",&t);
    while (t--)
    {
        getchar();
        scanf("%s",str);
        scanf("%d",&k);
        int len=strlen(str);
        long long ans=0;
        int l=0,r=0;
        int cnt=0;
        memset(ch,0,sizeof(ch));
        while (l<=r && l<len)
        {
            while (cnt<k && r<len)
            {
                ch[str[r]-'a']++;
                if (ch[str[r]-'a'] == 1) cnt++;
                r++;
            }
            if (cnt == k) ans+=len-r+1;
            if (ch[str[l]-'a'] == 1) cnt--;
            ch[str[l]-'a']--;
            l++;
        }
        printf("%lld\n",ans);
    }
    return 0;
}



4、Robot


分析:卡特蘭數加逆元,我拒絕,渣渣不會,望聚聚指點







 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章