5.28 模拟赛

二次联通门 : 怎么会有。。。

T1 打表找规律

T2 模拟

T3 矩阵快速幂

T4 mmp

T1 

Problem 1 双色球(ball.cpp/c/pas)

【题目描述】

    机房来了新一届的学弟学妹,邪恶的chenzeyu97发现一位学弟与他同名,于是他当起了善良的学长233

“来来来,学弟,我考你道水题检验一下你的水平……”

一个栈内初始有n个红色和蓝色的小球,请你按照以下规则进行操作

  1. 只要栈顶的小球是红色的,将其取出,直到栈顶的球是蓝色
  2. 然后将栈顶的蓝球变成红色
  3. 最后放入若干个蓝球直到栈中的球数为n

以上3步骤为一次操作

如栈中都是红色球,则操作停止,请问几次操作后停止

chenzeyu97出完题发现他自己不能AC所以想请你帮忙

【输入格式】

第一行为一个整数n,表示栈的容量为n

第二行为一个字符串,第i个字符表示自顶向下的第i个球的颜色,R代表红色,B代表蓝色

【输出格式】

一个整数表示操作数

【样例输入】

样例1:

3

RBR

样例2:

4

RBBR

【样例输出】

样例1:2

样例2:6

【样例解释】

样例1:

 

样例2:

 

【数据范围】

50%的数据,1<=n<=20

100%的数据,1<=n<=50

 

/*
    T1
    
    可以发现 
    
    把所有蓝球的深度i
    变为2 ^ (i - 1)后累加即为答案 
*/
#include <cstdio>
#include <cmath>

#define Max 300

void read (int &now)
{
    now = 0;
    register char word = getchar ();
    while (word < '0' || word > '9')
        word = getchar ();
    while (word >= '0' && word <= '9')
    {
        now = now * 10 + word - '0';
        word = getchar ();
    }
}

char line[Max];
int N;

int main (int argc, char *argv[])
{
    freopen ("ball.in","r",stdin);
    freopen ("ball.out","w",stdout);
    read (N);
    long long Answer = 0;
    scanf("%s", line);
    for (int i = 0; i < N; i++)
        if (line[i] == 'B') 
            Answer += pow (2, N - i - 1);
    printf ("%lld
", Answer);
    return 0;
}

 T2

Problem 2 魔方(cube.cpp/c/pas)

【题目描述】

ccy(ndsf)觉得手动复原魔方太慢了,所以他要借助计算机。

ccy(ndsf)家的魔方都是3*3*3的三阶魔方,大家应该都见过。



3的“顺时针”改为“逆时针”,即3 4以图为准。)
ccy(ndfs)从网上搜了一篇攻略,并找人翻译成了他自己会做的方法。现在告诉你他的魔方情况,以及他从网上搜到的攻略,请你求出最后魔方变成什么样子。

【输入格式】
   第一行,一串数字,表示从网上搜到的攻略。
   下面6*3行,每行3个数字,每三行表示魔方一个面的情况,六个面的顺序是前、后、左、右、上、下。

【输出格式】
   6*3行,表示处理后的魔方,形式同输入。

【样例输入】

23
121
221
111
123
321
111
123
321
132
132
231
132
121
112
233
332
111
333

【样例输出】

123
222
113
212
321
113
122
321
132
121
333
121
211
312
113
331
111
331

【样例解释】


【数据范围】

40%的数据,攻略的长度小于5且仅有4种操作的其中一种

100%的数据,攻略的长度小于100

/*
    T2 
    自己在纸上画画就明白了。。 

*/ 
#include <cstring>
#include <cstdio>

#define Max 30

void read (int &now)
{
    now = 0;
    register char word = getchar ();
    while (word < '0' || word > '9')
        word = getchar ();
    while (word >= '0' && word <= '9')
    {
        now = now * 10 + word - '0';
        word = getchar ();
    }
}


class Mofa_Type 
{
    private :
        
        int map[Max][Max][Max];
        
        int now[Max][Max][Max];
        
        inline void Update ()
        {
            for (int i = 1; i <= 6; i++)
                for (int j = 1; j <= 3; j++)
                    for (int k = 1; k <= 3; k++)
                    {
                        if (now[i][j][k])
                            map[i][j][k] = now[i][j][k];
                    }
            memset (now, 0, sizeof now);
        }
        
    public :
        
        void Rotate_1 ()
        {
            for (int i = 1; i <= 3; i++)
            {
                now[1][i][3] = map[6][i][3];
                now[6][i][3] = map[2][i][3];
                now[2][i][3] = map[5][i][3];
                now[5][i][3] = map[1][i][3];
            }
            for (int i = 1; i <= 3; i++)
                for (int j = 1; j <= 3; j++)
                    now[4][j][4 - i] = map[4][i][j];
            Update ();
        }
        
        void Rotate_2 ()
        {
            for (int i = 1; i <= 3; i++)
            {
                now[1][i][3] = map[5][i][3];
                now[5][i][3] = map[2][i][3];
                now[2][i][3] = map[6][i][3];
                now[6][i][3] = map[1][i][3];
            }
            for (int i = 1; i <= 3; i++)
                for (int j = 1; j <= 3; j++)
                    now[4][4 - j][i] = map[4][i][j];
            Update ();
        }
        
        void Rotate_3 ()
        {
            for (int i = 1; i <= 3; i++)
            {
                now[1][1][i] = map[3][1][i];
                now[3][1][i] = map[2][1][i];
                now[2][1][i] = map[4][1][i];
                now[4][1][i] = map[1][1][i];
            }
            for (int i = 1; i <= 3; i++)
                for (int j = 1; j <= 3; j++)
                    now[5][j][4 - i] = map[5][i][j];
            Update ();
        }
        
        void Rotate_4 ()
        {
            for (int i = 1; i <= 3; i++)
            {
                now[1][1][i] = map[4][1][i];
                now[4][1][i] = map[2][1][i];
                now[2][1][i] = map[3][1][i];
                now[3][1][i] = map[1][1][i];
            }
            for (int i = 1; i <= 3; i++)
                for (int j = 1; j <= 3; j++)
                    now[5][4 - j][i] = map[5][i][j];
            Update ();
        }
        
        void Key_In_Date (int i, int j, int k, int now)
        {
            map[i][j][k] = now;
        }
        
        void Print ()
        {
            for (int i = 1; i <= 6; i++)
                for (int j = 1; j <= 3; j++)
                {
                    for (int k = 1; k <= 3; k++)
                        printf ("%d", map[i][j][k]);
                    putchar ('
');
                }
        }
};

Mofa_Type Flandre;

char make[Max];

int main (int argc, char *argv[])
{
    freopen ("cube.in", "r", stdin);
    freopen ("cube.out", "w", stdout);
    scanf ("%s", make);
    char line[5];
    for (int i = 1; i <= 6; i++)
        for (int j = 1; j <= 3; j++)
        {
            scanf ("%s", line);
            for (int k = 0; k < 3; k++)
                Flandre.Key_In_Date (i, j, k + 1, line[k] - '0'); 
        }
    int N = strlen (make);
    for (int i = 0; i < N; i++)
    {
        if (make[i] == '1')
            Flandre.Rotate_1 ();
        else if (make[i] == '2')
            Flandre.Rotate_2 ();
        else if (make[i] == '3')
            Flandre.Rotate_3 ();
        else if (make[i] == '4')
            Flandre.Rotate_4 ();  
    }
    Flandre.Print (); 
    return 0;
}

T3

Problem 3 czy的后宫(harem.cpp/c/pas)

【题目描述】

czy要妥善安排他的后宫,他想在机房摆一群妹子,一共有n个位置排成一排,每个位置可以摆妹子也可以不摆妹子。有些类型妹子如果摆在相邻的位置(隔着一个空的位置不算相邻),就不好看了。假定每种妹子数量无限,求摆妹子的方案数。

【输入格式】

输入有m+1行,第一行有两个用空格隔开的正整数n、m,m表示妹子的种类数。接下来的m行,每行有m个字符1或0,若第i行第j列为1,则表示第i种妹子第j种妹子不能排在相邻的位置,输入保证对称。(提示:同一种妹子可能不能排在相邻位置)。

【输出格式】

输出只有一个整数,为方案数(这个数字可能很大,请输出方案数除以1000000007的余数。

【样例输入】

2 2

01

10

【样例输出】

7

【样例说明】

七种方案为(空,空)、(空,1)、(1、空)、(2、空)、(空、2)、(1,1)、(2,2)。

【数据范围】

20%的数据,1<n≤5,0<m≤10。

60%的数据,1<n≤200,0<m≤100。

100%的数据,1<n≤1000000000,0<m≤100。

注:此题时限1.5s是因为本评测机跑太慢,大家正常做

但写的太丑可能T一俩个点

/*
    T3
    
    原方程为 
    if (map[j][k])
        dp[i][j] = (dp[i][j] + dp[i - 1][k]) % Mod
    其中 dp[i][j] 表示的是第i个位置放j号妹子的方案数 
    
    然后就是由上一个位置放第k个妹子的方案数转移而来
    
    然后变成矩阵的形式就行了
    此题的矩阵还是很好推的
    
    
    但是却超时三个点。。。 

*/ 
#include <cstring>
#include <cstdio>

#define Max 300

void read (long long &now)
{
    now = 0;
    register char word = getchar ();
    while (word < '0' || word > '9')
        word = getchar ();
    while (word >= '0' && word <= '9')
    {
        now = now * 10 + word - '0';
        word = getchar ();
    }
}

long long M, N;

#define Mod 1000000007

long long Answer = 0;
char line[Max];

class Martix_Type
{
    private :

        struct Martix_Date
        {
            long long martix[Max][Max];

            Martix_Date operator * (const Martix_Date &a) const
            {
                Martix_Date now;
                for (long long i = 0; i <= M; i++)
                    for (long long j = 0; j <= M; j++)
                    {
                        now.martix[i][j] = 0;
                        for (long long k = 0; k <= M; k++)
                            now.martix[i][j] = (now.martix[i][j] + martix[i][k] * a.martix[k][j]) % Mod;
                    }
                return now;
            }
        };

        Martix_Date Result, A;
        
    public :

        void Make_Answer ()
        {
            for (int i = 0; i <= M; i++)
                for (int j = 0; j <= M; j++)
                {
                    A.martix[i][0] = 1;
                    A.martix[0][i] = 1;
                    Result.martix[0][i] = 1;
                    Result.martix[i][0] = 1;
                }
            Fast_Pow (N - 1);
            for (int i = 0; i <= M; i++)
                Answer = (Answer + Result.martix[i][0]) % Mod;
        }
        
        void Fast_Pow (long long p)
        {
            while (p)
            {
                if (p & 1)
                    Result = A * Result;
                A = A * A;
                p >>= 1;
            }
        }
        
        void Prepare ()
        {
            for (int i = 1; i <= M; i++)
            {
                scanf ("%s", line + 1);
                for (int j = 1; j <= M; j++)
                    if (line[j] == '0')
                    {
                        Result.martix[i][j] = 1;
                        A.martix[i][j] = 1;
                    }
            }
        }
};

Martix_Type Make;


int main (int argc, char *argv[])
{
    freopen ("harem.in", "r", stdin);
    freopen ("harem.out", "w", stdout);
    read (N);
    read (M);
    Make.Prepare (); 
    Make.Make_Answer (); 
    printf ("%lld", Answer);
    return 0;
}

Problem 4 mex(mex.cpp/c/pas)

【题目描述】

 

【输入格式】

 

【输出格式】

 

【样例输入】

7 5

0 2 1 0 1 3 2

1 3

2 3

1 4

3 6

2 7

【样例输出】

3

0

3

2

4

【样例解释与数据范围】

 

/*
    T4
    
    不会做。。。
    老早就听别人说是莫队。。
    可是不会莫队 

    就用堆+一堆特判
    想骗点分。。
    结果第一个点WA
    其余点TLE
     
*/
#include <cstdio>
#include <vector>
#include <queue>

#define Max 1000001

void read (int &now)
{
    now = 0;
    register char word = getchar ();
    while (word < '0' || word > '9')
        word = getchar ();
    while (word >= '0' && word <= '9')
    {
        now = now * 10 + word - '0';
        word = getchar ();
    }
}

inline int min (int a, int b)
{
    return a < b ? a : b;
}

inline int max (int a, int b)
{
    return a > b ? a : b;
}

int N, M;

int number[Max];


int main (int argc, char *argv[])
{
    freopen ("mex.in", "r", stdin);
    freopen ("mex.out", "w", stdout);
    read (N);
    read (M);
    for (int i = 1; i <= N; i++)
        read (number[i]);
    int x, y;
    int Count = 0;
    while (M--)
    {
        bool flag = false;
        read (x);
        read (y);
        std :: priority_queue <int, std :: vector<int>, std :: greater<int> > Heap;
        for (int i = x; i <= y; i++)
            Heap.push (number[i]);
        if (Heap.top () >= 1)
        {
            printf ("%d
", Heap.top () - 1);
            continue;
        } 
        int now;
        while (!Heap.empty ())
        {
            now = Heap.top ();
            Heap.pop (); 
            if (now + 1 != Heap.top () && now != Heap.top ())
            {
                printf ("%d
", now + 1);
                flag = true;
                break;
            }
        }
        if (flag == false)
            printf ("%d
", now + 1);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/ZlycerQan/p/6915733.html