传送门

A There Are Two Types Of Burgers

简单的枚举每一种情况,来贪心的选择

//
//  Author : north_h
//  File : A.cpp
//  Time : 2023/7/24/11:59
//                  _   _         _     
// _ __   ___  _ __| |_| |__     | |__  
//| '_ \ / _ \| '__| __| '_ \    | '_ \ 
//| | | | (_) | |  | |_| | | |   | | | |
//|_| |_|\___/|_|   \__|_| |_|___|_| |_|
//                          |_____|     

#include<bits/stdc++.h>

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a, b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.begin(),a.end()
#define int128 __int128
#define endl '\n'
const int N = 10010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;

using namespace std;

void solve() {
    int b, p, f, h, c;
    cin >> b >> p >> f >> h >> c;
    int ans = 0;
    for (int i = 0; (i * 2) <= b && i <= p; i++) {
        int x = b - i * 2;
        int val = i * h + min(x / 2, f) * c;
        ans=max(ans,val);
    }
    cout << ans << endl;
}

int main() {
    IOS;
    int h_h = 1;
    cin >> h_h;
    while (h_h--)solve();
    return 0;
}

B Square Filling

这个题没有规定次数,直接枚举整个矩阵的位置,再2x2的方格里,如果全部都为1,就标记为true,最后验证vis矩阵是否和所给的矩阵相同即可,这个题因为空间不小心开大了还MLE了一发,不好说

//
//  Author : north_h
//  File : B.cpp
//  Time : 2023/7/24/12:06
//                  _   _         _     
// _ __   ___  _ __| |_| |__     | |__  
//| '_ \ / _ \| '__| __| '_ \    | '_ \ 
//| | | | (_) | |  | |_| | | |   | | | |
//|_| |_|\___/|_|   \__|_| |_|___|_| |_|
//                          |_____|     

#include<bits/stdc++.h>

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a, b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.begin(),a.end()
#define int128 __int128
#define endl '\n'
const int N = 100;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;

using namespace std;

int n,m;
int g[N][N];
int vis[N][N];

void solve() {
    cin >> n >> m;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> g[i][j];
            if (g[i][j] == 0)cnt++;
        }
    }
    if (cnt == n * m) {
        cout << 0 << endl;
        return;
    }
    vector <PII> ans;
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < m - 1; j++) {
            if (g[i][j] == 1 && g[i][j + 1] == 1 && g[i + 1][j] == 1 && g[i + 1][j + 1] == 1) {
                ans.push_back({i + 1, j + 1});
                vis[i][j] = vis[i][j + 1] = vis[i + 1][j] = vis[i + 1][j + 1] = 1;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (vis[i][j] != g[i][j]) {
                cout << -1 << endl;
                return;
            }
        }
    }
    cout << ans.size() << endl;
    for (auto i: ans)cout << i.fi << ' ' << i.se << endl;
}

int main() {
    IOS;
    int h_h = 1;
    //cin >> h_h;
    while (h_h--)solve();
    return 0;
}

C Gas Pipeline

dp,只有两个状态,要么用高的支柱,要么用低的支柱,因为最开始只能为低支柱,送总第一个位置开始推后面的状态,要注意一个特殊情况,如果这个位置是高支柱,那么前面一定是高支柱,最后也一定是低支柱

//
//  Author : north_h
//  File : C.cpp
//  Time : 2023/7/24/12:26
//                  _   _         _     
// _ __   ___  _ __| |_| |__     | |__  
//| '_ \ / _ \| '__| __| '_ \    | '_ \ 
//| | | | (_) | |  | |_| | | |   | | | |
//|_| |_|\___/|_|   \__|_| |_|___|_| |_|
//                          |_____|     

#include<bits/stdc++.h>

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a, b) memcopy(a,sizeof b,b)
#define int long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.begin(),a.end()
#define int128 __int128
#define endl '\n'
const int N = 200010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;

using namespace std;

int  dp[N][2];

void solve() {
    met_x(dp);
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    dp[0][0] = b;
    for (int i = 0; i < n; i++) {
        if (s[i] == '1')dp[i + 1][1] = dp[i][1] + a + b * 2;
        else {
            dp[i + 1][0] = min(dp[i][0] + a + b, dp[i][1] + a * 2 + b);
            dp[i + 1][1] = min(dp[i][0] + a*2 + b * 2, dp[i][1] + a + b * 2);
        }
    }
    cout << dp[n][0] << endl;
}

int32_t main() {
    IOS;
    int h_h = 1;
    cin >> h_h;
    while (h_h--)solve();
    return 0;
}

D Number Of Permutations

正向求解问题非常难,所以我们可以使用容斥原理来求,先求第一个序列非递减的数量,再求第二序列非递减的数量,最后再求两个同时非递减的数量,最后总情况减去两个非递减的情况再将上两个同是非递减的数量,防止加多,这里要特别注意就是可能不存在两个数列有同事非递减的情况,我们按第一列排序,来判断第二列是否非递减即可,如果时非递减,俺么存在重合的,然后不是非递减,那么就不存在重合的

//
//  Author : north_h
//  File : D.cpp
//  Time : 2023/7/24/15:10
//                  _   _         _     
// _ __   ___  _ __| |_| |__     | |__  
//| '_ \ / _ \| '__| __| '_ \    | '_ \ 
//| | | | (_) | |  | |_| | | |   | | | |
//|_| |_|\___/|_|   \__|_| |_|___|_| |_|
//                          |_____|     

#include<bits/stdc++.h>

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a, b) memcopy(a,sizeof b,b)
#define int long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.begin(),a.end()
#define int128 __int128
#define endl '\n'
const int N = 300010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;

using namespace std;

int n;
int fact[N];
map<int,int> mp1,mp2;
map<PII,int> mp3;
vector<PII> a;

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        mp1[x]++;
        mp2[y]++;
        mp3[{x, y}]++;
        a.emplace_back(x, y);
    }
    fact[0] = 1;
    for (int i = 1; i <= n; i++)fact[i] = fact[i - 1] * i % MOD;
    int res1 = 1;
    int res2 = 1;
    int res3 = 1;
    for (auto i: mp1)res1 = res1 * fact[i.se] % MOD;
    for (auto i: mp2)res2 = res2 * fact[i.se] % MOD;
    for (auto i: mp3)res3 = res3 * fact[i.se] % MOD;
    sort(ALL(a));
    bool ok = true;
    for (int i = 1; i < a.size(); i++) if (a[i].se < a[i - 1].se)ok = false;
    int ans = (fact[n] - res1 + MOD) % MOD;
    ans = (ans - res2 + MOD) % MOD;
    if (ok)ans = (ans + res3) % MOD;
    cout << ans % MOD << endl;
}

int32_t main() {
    IOS;
    int h_h = 1;
    //cin >> h_h;
    while (h_h--)solve();
    return 0;
}

E XOR Guessing

又是一道交互题,只有两次询问,要知道一个2^14-1的数,所以可以是使用位运算的知识,先求二进制前七位,再求二进制后七位,最后把得到的前七位和后七位拼在一起即可。

//
//  Author : north_h
//  File : E.cpp
//  Time : 2023/7/24/15:10
//                  _   _         _     
// _ __   ___  _ __| |_| |__     | |__  
//| '_ \ / _ \| '__| __| '_ \    | '_ \ 
//| | | | (_) | |  | |_| | | |   | | | |
//|_| |_|\___/|_|   \__|_| |_|___|_| |_|
//                          |_____|     

#include<bits/stdc++.h>

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a, b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.begin(),a.end()
#define int128 __int128
#define endl '\n'
const int N = 10010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;

using namespace std;

void solve() {
    cout << "?" << ' ';
    for (int i = 1; i <= 100; i++)cout << i << ' ';
    cout.flush();
    int n;
    cin >> n;//高七位
    cout << "?" << ' ';
    for (int i = 1; i <= 100; i++)cout << (i << 7) << ' ';
    cout.flush();
    int m;
    cin >> m;//低七位
    int x = n & 16256;
    x >>= 7, x <<= 7;
    int y = m & 127;
    y <<= 7, y >>= 7;
    cout << "! ";
    cout << (x | y) << endl;
}

int main() {
    IOS;
    int h_h = 1;
    //cin >> h_h;
    while (h_h--)solve();
    return 0;
}