2020杭电多校(5)补题

1009.Paperfolding

Paperfolding

题意

纸张对折,允许上下左右四个方向,给出n次操作,问n次折叠后从中心横竖裁剪后可得到多少张纸

思路

手动折纸发现左右是等价操作,上下也是

推出 ( 2 i + 1 ) × ( 2 n − i + 1 ) (2^i + 1) \times (2^{n-i} + 1) (2i+1)×(2ni+1)

i i i次上下, n − i n - i ni次左右

数学期望为
$ E(x) = \frac{1}{2n}\sum_{i=0}n C_ni(2i + 1)(2^{n-i} + 1) =1 + 2^n + C_ni(2i+2{n-i})\frac{1}{2n}=1 + 2^n+2 \times 3n/2n$

因为 ( 1 + 2 ) n = C n i 2 i (1 + 2)^n = C_n^i2^i (1+2)n=Cni2i

代码

/*************************************************************************
 > FileName:
 > Author:      Lance
 > Mail:        lancelot_hcs@qq.com
 > Date:        9102.1.8
 > Description:
 ************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = 998244353;
#define debug(a) cout << "*" << a << "*" << endl
const int INF = 0x3f3f3f3f;//int2147483647//ll9e18//unsigned ll 1e19
const int maxn = 1000005;
//sacnf("%lf") printf("%f")
ll read()
{
    ll x = 0,f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
        f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
ll t, n;
ll qpow(ll x, ll n, ll p) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = res * x % p;
        }
        x = x * x % p;
        n >>= 1;
    }
    return res;
}

ll tem[maxn];
ll rev(ll a) {
    return qpow(a, mod - 2, mod);
}
void solve()
{
    t = read();
    while (t--) {
        n = read();
        ll tem = 2 * qpow(3, n, mod) % mod;
        tem = tem * rev(qpow(2, n, mod)) % mod;
        tem = (tem + 1 + qpow(2, n, mod)) % mod;
        printf("%lld\n", tem);
    }
}

int main()
{

//    freopen("F:/Overflow/in.txt","r",stdin);
//    ios::sync_with_stdio(false);
    solve();
    return 0;
}

1003.Boring Game

Boring Game

题意

纸张折叠无聊的游戏

思路

根据题解:(比赛时没有看出这么简单的规律)

x 1 [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ] → [ 8 9 7 10 6 11 5 12 4 13 3 14 2 15 1 16 ] → [ 12 5 4 13 11 6 3 14 10 7 2 15 9 8 1 16 ] x 1\left[ \begin{matrix} 1 \\2 \\3 \\4 \\5 \\6 \\7 \\8 \\9 \\10 \\11 \\12 \\13 \\14 \\15 \\16\end{matrix}\right] \to \left[\begin{matrix} 8&9\\7&10\\6&11\\5&12\\4&13\\3&14\\2&15\\1&16 \end{matrix}\right] \to \left[\begin{matrix} 12&5&4&13\\11&6&3&14\\10&7&2&15\\9&8&1&16 \end{matrix}\right] x1123456789101112131415168765432191011121314151612111095678432113141516
发现规律,每次操作都是,上半部分翻转,置于左侧,下半部分上移,对齐上半部分

根据此规律模拟即可

代码

/*************************************************************************
 > FileName:
 > Author:      Lance
 > Mail:        lancelot_hcs@qq.com
 > Date:        9102.1.8
 > Description:
 ************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9 + 7;
#define debug(a) cout << "*" << a << "*" << endl
const int INF = 0x3f3f3f3f;//int2147483647//ll9e18//unsigned ll 1e19
const int maxn = 1000005;
//sacnf("%lf") printf("%f")
ll read()
{
    ll x = 0,f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
        f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
vector<int> G[1220];
int t, n, k;
ll qpow(ll n, ll x) {

    ll res = 1;
    while (x) {
        if (x & 1) {
            res = (res * n) % mod;
        }
        n = (n * n) % mod;
        x >>= 1;
    }
    return res;
}
int a[maxn];
int tem[maxn];

void look(int k) {
    for (int i = 1; i <= k; i++) {
        for (auto it : G[i]) {
            cout << it << ' ';
        }
        puts("");
    }
}

void solve()
{
    t = read();
    while (t--) {
        n = read(), k = read();
        ll all = 2 * n * qpow(2, k);
        ll row = qpow(2, k);
        for (int i = 0; i <= row; i++) G[i].clear();
        for (int i = 1; i <= all; i++) {
            a[i] = read();
            G[1].push_back(a[i]);
        }
        for (int i = 1; i <= k; i++) {
            int tem = 1 << (i - 1);       // 操作行数
            int con = all / (tem * 2);    // 当前中点
            for (int j = 1; j <= tem; j++) {
                int to = 2 * tem - j + 1;
                reverse(G[j].begin(), G[j].begin() + G[j].size() / 2);      // 反转
                G[to].assign(G[j].begin(), G[j].begin() + G[j].size() / 2); // 拷贝

                for (int k = 0; k < con; k++) G[j][k] = G[j][k + con];
                for (int k = 1; k <= con; k++) G[j].pop_back();
//                look(tem * 2);
            }
        }
        for (int i = 0; i < n * 2; i++)
            for (int j = row; j >= 1; j--) {
                if (j != row || i != 0) printf(" ");
                cout << G[j][i];
            }
        puts("");
    }
}
/*
10
2 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 1
1 2 3 4
1 2
1 2 3 4 5 6 7 8
*/
int main()
{

//    freopen("F:/Overflow/in.txt","r",stdin);
//    ios::sync_with_stdio(false);
    solve();
    return 0;
}

1012.Set1

Set1

题意

思路

代码


1007.Tree

tree

题意

思路

代码


参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值