[hihocoder][Offer收割]编程练习赛64

Posted dramstadt

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[hihocoder][Offer收割]编程练习赛64相关的知识,希望对你有一定的参考价值。

公平划分

若条件满足,则所有数异或和为零,这时候随便分都可以,答案为2^n-2,否则答案为0

技术分享图片
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII;

void makedata() {
    freopen("input.txt", "w", stdout);
    fclose(stdout);
}

int n;
lint a[100];

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    //makedata();
    std::ios::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    lint x = a[0];
    for (int i = 1; i < n; i++) x ^= a[i];
    if (x != 0) cout << 0 << endl;
    else cout << (1LL << n) - 2 << endl;
    return 0;
}
View Code

配对

状态压缩,dp[i][j]表示进行到第j个女生,所有男生匹配状况为i时的方案数

技术分享图片
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII;

void makedata() {
    freopen("input.txt", "w", stdout);
    fclose(stdout);
}

lint dp[5000][15];

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    //makedata();
    std::ios::sync_with_stdio(0), cin.tie(0);
    int n, a[15], b[15];
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < (1 << n); j++) {
            for (int k = 1; k <= n; k++) {
                if (!(j & (1 << (k - 1))) && a[k] <= b[i]) {
                    dp[j + (1 << (k - 1))][i] += dp[j][i - 1];
                }
            }
        }
    }
    cout << dp[(1 << n) - 1][n] << endl;
    return 0;
}
View Code

字符串问题

贪心

技术分享图片
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII;

void makedata() {
    freopen("input.txt", "w", stdout);
    fclose(stdout);
}
string s;
int a[26][110000];
int find(int l, int r, int c) {
    if (l >= r) return -1;
    int sum;
    if (l == 0) sum = a[c][r - 1];
    else sum = a[c][r - 1] - a[c][l - 1];
    if (sum == 0) return -1;
    if (l + 1 == r) {
        if (s[l] - a == c) return l;
        else return -1;
    }
    int mid = (l + r) / 2;
    int ll = find(l, mid, c);
    if (ll != -1) return ll;
    else return find(mid, r, c);
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    //makedata();
    std::ios::sync_with_stdio(0), cin.tie(0);
    cin >> s;
    int n = s.length();
    memset(a, 0, sizeof(a));
    a[s[0] - a][0] = 1;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 26; j++) a[j][i] = a[j][i - 1];
        a[s[i] - a][i]++;
    }
    int m = 1, ans = 1;
    while (m < n) {
        if (find(0, m, (int)(s[m] - a)) == -1) m++, ans++;
        else {
            int l = -1, p = m;
            while (p < n) {
                l = find(l + 1, m, (int)(s[p] - a));
                if (l == -1) {
                    m = p;
                    ans++;
                    break;
                }
                p++;
            }
            m = p;
            if (p == n) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
View Code

公共山峰

emmm...

以上是关于[hihocoder][Offer收割]编程练习赛64的主要内容,如果未能解决你的问题,请参考以下文章

[hihocoder] [Offer收割]编程练习赛43

[hihocoder][Offer收割]编程练习赛58

hihocoder offer收割编程练习赛8 A

hihocoder offer收割编程练习赛8 B

hihocoder offer收割编程练习赛11 C 岛屿3

hihocoder offer收割编程练习赛12 C 矩形分割