2020年第十四届山东大学程序设计竞赛(重现赛)题解(C D F L)

2020年第十四届山东大学程序设计竞赛(重现赛)题解(C D F L)_第1张图片

#include 
#include 

using namespace std;

int main()
{
     
    string a, b = "", c = "";
    cin >> a;
    for (int i = 0; i < a.size(); ++i)
    {
     
        if (i % 2 == 0)
            b += a[i];
        else
            c += a[i];
    }
    cout << b << c << endl;
    return 0;
}

2020年第十四届山东大学程序设计竞赛(重现赛)题解(C D F L)_第2张图片
矩阵乘法

#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

typedef long long ll;

const int N = 3;
double n, p;
ll m;

struct node{
     
    double g[N + 2][N + 2];//结构体存储矩阵
}f, res;

//构造单位矩阵
void matrixI(node &x)
{
     
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= N; ++j)
        {
     
            if (i == j)x.g[i][j] = 1.0;
            else x.g[i][j] = 0.0;
        }
}

//矩阵乘法
void matrixMultiple(node &x, node &y, node &z)
{
     
    memset(z.g, 0, sizeof(z.g));

    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= N; ++j)
            for (int k = 1; k <= N; ++k)
            {
     
                z.g[i][k] += x.g[i][j] * y.g[j][k];
                // if (z.g[i][k] >= m)z.g[i][k] %= m;
            }
}

//快速幂
void matrixMuli(int k)
{
     
    matrixI(res);

    node tmp = f, t;

    while (k)
    {
     
        if (k & 1)
        {
     
            matrixMultiple(res, tmp, t);
            res = t;
        }
        matrixMultiple(tmp, tmp, t);
        tmp = t;
        k >>= 1;
    }
}

double solve()
{
     
    if (n == 1)return 0.5;
    // if (n == 2) return 0.75;
    matrixMuli(n - 1);
    double ret = res.g[1][1] * 1.0 / 2 + res.g[1][2] * 1.0 / 4 + res.g[1][3] * 1.0 / 2;

    // if (ret >= m)ret -= m;

    return ret;
}

int main()
{
     
    // ios::sync_with_stdio(false);

    cin >> n;

    // m = p;

    f.g[1][1] = 1; f.g[1][2] = 1; f.g[1][3] = 0;
    f.g[2][1] = 0; f.g[2][2] = 0.5; f.g[2][3] = 0.25;
    f.g[3][1] = 0; f.g[3][2] = 1; f.g[3][3] = 0;

    double res = solve();

    printf("%.10lf", res);

    return 0;
}

2020年第十四届山东大学程序设计竞赛(重现赛)题解(C D F L)_第3张图片

#include 
#include 
#include 
#include 

using namespace std;

int main()
{
     
    long long y;
    cin >> y;
    cout << "1" << endl;
    cout << y << endl;
    long long k = y;
    vector<long long>v1;
    while (k) 
    {
     
        v1.push_back(k % 2);
        k /= 2;
    }
    vector<long long>ans;
    ans.push_back(0);
    for (long long i = 0; i < v1.size(); ++i) 
    {
     
        if (v1[i] == 1) 
        {
     
            long long num = ans.size();
            long long ka = pow(2, i);
            ans.push_back(ka);
            for (int j = 1; j < num; ++j)
            {
     
                ans.push_back(ka + ans[j]);
            }
        }
    }
    // ans.push_back(y);
    // ans.push_front(0);
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); ++i)
    {
     
        cout << ans[i] << endl;
    }
    return 0;
}

2020年第十四届山东大学程序设计竞赛(重现赛)题解(C D F L)_第4张图片

#include 
#include 

using namespace std;

int main()
{
     
    int x, n;
    cin >> x >> n;
    x += n % 7;
    x %= 7;
    if (x == 0)
        x = 7;
    cout << x << endl;
    return 0;
}

你可能感兴趣的:(2020年第十四届山东大学程序设计竞赛(重现赛)题解(C D F L))