2020 Multi-University Training Contest 10

Anti-hash Test
Network Test

Mine Sweeper

2020杭电多校 第十场 1003 Mine Sweeper 构造
随机生成

#include <bits/stdc++.h>
using namespace std;
#define between(x, a, b) (a<=x && x<=b)
const int dir[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
int n;

map<int, vector<vector<char>>> mp;

int solve(vector<vector<char>> a) {
    int r = a.size();
    int c = a[0].size();
    int res = 0;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            if (a[i][j] == '.') {
                int cnt = 0;
                for (int l = 0; l < 8; l++) {
                    int dx = i + dir[l][0];
                    int dy = j + dir[l][1];
                    if (between(dx, 0, r - 1) && between(dy, 0, c - 1) && a[dx][dy] == 'X') {
                        cnt++;
                    }
                }
                res += cnt;
            }
        }
    }
    return res;
}

void init() {
    srand((int) time(0));
    for (int k = 1; k <= 50000; k++) {
        int r = (rand() % 25) + 1;
        int c = (rand() % 25) + 1;
        vector<vector<char>> a(r, vector<char>(c));
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                a[i][j] = (rand() % 2) ? 'X' : '.';
            }
        }
        int sum = solve(a);
        mp[sum] = a;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    init();
    int T;
    cin >> T;
    for (int cs = 1; cs <= T; cs++) {
        cin >> n;
        vector<vector<char>> a = mp[n];

        int r = a.size();
        int c = a[0].size();
        cout << r << " " << c << endl;
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                cout << a[i][j] << (j == c - 1 ? "\n" : "");
            }
        }
    }
    return 0;
}

Permutation Counting
Tree Cutting
Divide and Conquer
Coin Game
I do not know Graph Theory!
Photography
Tic-Tac-Toe-Nim

Task Scheduler

每一个状态 i i i 的期望值都有如下公式对应

E i = ∑ p i j × E j + 1 E_i=\sum p_{ij}\times E_j +1 Ei=pij×Ej+1
其中 j j j 是状态 i i i 能够到达的所有的下一个状态

假设存在一个任务排列 { p 1 , p 2 , . . . p n } \{p_1,p_2,...p_n\} {p1,p2,...pn} 使得目标期望最小化,则存在

E 1 = ( 1 − C m − k t p 1 ) C m t p 1 × E 1 + C m − k t p 1 C m t p 1 × E 2 + 1 E_1=\cfrac{(1-C^{t_{p_1}}_{m-k})}{C^{t_{p_1}}_m}\times E_1+\cfrac{C^{t_{p_1}}_{m-k}}{C^{t_{p_1}}_m}\times E_2+1 E1=Cmtp1(1Cmktp1)×E1+Cmtp1Cmktp1×E2+1

其中 ( 1 − C m − k t p 1 ) C m t p 1 \cfrac{(1-C^{t_{p_1}}_{m-k})}{C^{t_{p_1}}_m} Cmtp1(1Cmktp1) 为选中了任意一个干坏事的人而停留在当前状态的概率(反正就是那k个人中的一个)

C m − k t p 1 C m t p 1 \cfrac{C^{t_{p_1}}_{m-k}}{C^{t_{p_1}}_m} Cmtp1Cmktp1 则是顺利进入下一个状态的概率, 1 1 1 是当前状态进入到下一个状态的代价

观察到左右同时拥有 E 1 E_1 E1 ,进一步化简得到如下公式

E 1 − E 2 = C m t p 1 C m − k t p 1 E_1-E_2=\cfrac{C^{t_{p_1}}_m}{C^{t_{p_1}}_{m-k}} E1E2=Cmktp1Cmtp1

再继续推下一个状态 E 2 E_2 E2
E 2 = ( 1 − C m − t p 1 − k t p 2 ) C m − t p 1 t p 2 × E 2 + C m − t p 1 − k t p 2 C m − t p 1 t p 2 × E 3 + 1 E_2=\cfrac{(1-C^{t_{p_2}}_{m-t_{p_1}-k})}{C^{t_{p_2}}_{m-t_{p_1}}}\times E_2+\cfrac{C^{t_{p_2}}_{m-t_{p_1}-k}}{C^{t_{p_2}}_{m-t_{p_1}}}\times E_3+1 E2=Cmtp1tp2(1Cmtp1ktp2)×E2+Cmtp1tp2Cmtp1ktp2×E3+1

E 2 − E 3 = C m − t p 1 t p 2 C m − t p 1 − k t p 2 E_2-E_3=\cfrac{C^{t_{p_2}}_{m-t_{p_1}}}{C^{t_{p_2}}_{{m-t_{p_1}}-k}} E2E3=Cmtp1ktp2Cmtp1tp2

到这一步应该都看出来接下来应该怎么做了:
( E 1 − E 2 ) + ( E 2 − E 3 ) + . . . . + ( E n − 1 − E n ) (E_1-E_2)+(E_2-E_3)+....+(E_{n-1}-E_n) (E1E2)+(E2E3)+....+(En1En)
E 1 − E n = C m t p 1 C m − k t p 1 + C m − t p 1 t p 2 C m − t p 1 − k t p 2 + . . . . + C m − ∑ t p i t p n C m − ∑ t p i − k t p n E_1-E_n=\cfrac{C^{t_{p_1}}_m}{C^{t_{p_1}}_{m-k}}+\cfrac{C^{t_{p_2}}_{m-t_{p_1}}}{C^{t_{p_2}}_{{m-t_{p_1}}-k}}+....+\cfrac{C^{t_{p_{n}}}_{m-\sum t_{p_i}}}{C^{t_{p_n}}_{m-\sum t_{p_i}-k}} E1En=Cmktp1Cmtp1+Cmtp1ktp2Cmtp1tp2+....+CmtpiktpnCmtpitpn

一般都令 E n = 0 E_n=0 En=0 E 1 E_1 E1 即为官方题解上的那个公式
在这里插入图片描述
emmmm 证明不会证,凭感觉猜的,n这个范围差点让我错过这道题

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m, k;
struct node {
    int id, t;
} a[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    int T;
    cin >> T;
    for (int cs = 1; cs <= T; cs++) {
        cin >> n >> m >> k;
        for (int i = 1; i <= n; i++) {
            cin >> a[i].t;
            a[i].id = i;
        }
        if (k == 0) {
            for (int i = 1; i <= n; i++) {
                cout << i << (i == n ? "\n" : " ");
            }
        } else {
            sort(a + 1, a + 1 + n, [](node x, node y) {
                if (x.t == y.t) return x.id < y.id;
                return x.t > y.t;
            });
            for (int i = 1; i <= n; i++) {
                cout << a[i].id << (i == n ? "\n" : " ");
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值