首页 > 其他分享 >Educational Codeforces Round 71

Educational Codeforces Round 71

时间:2023-07-24 19:15:22浏览次数:35  
标签:Educational int res ans Codeforces long cin 71 cnt

A. There Are Two Types Of Burgers

#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve() {
    int b, p, f, h, c;
    cin >> b >> p >> f>> h >> c;
    b /= 2;
    int res = 0;
    for (int i = 0, j; i <= min(b, p); i++) {
        j = min(b - i, f);
        res = max(res, i * h + j * c);
    }
    cout << res << "\n";
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

B. Square Filling

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 55;
int a[N][N], b[N][N];

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];

    vector<pair<int, int>> res;
    for (int i = 1; i < n; i++)
        for (int j = 1; j < m; j++){
            if( a[i][j] == 1 && a[i][j+1] == 1 && a[i+1][j] == 1 && a[i+1][j+1] == 1 )
                b[i][j] = b[i+1][j] = b[i][j+1] = b[i+1][j+1] = 1 , res.emplace_back( i , j );
        }
    for( int i = 1 ; i <= n ; i ++ )
        for( int j = 1 ; j <= m ; j ++ )
            if( a[i][j] != b[i][j] ){
                cout << "-1";
                return 0;
            }
    cout << res.size() << "\n";
    for( auto [x,y] : res )
        cout << x << " " << y << "\n";

            return 0;
}

C. Gas Pipeline

\(f[i][0/1]\)表示第\(i\)位在低或高时的花费,然后枚举前一位在高还是低即可

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int inf = 1e18;

void solve() {
    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;
    vector<array<int, 2>> f(n + 1, {inf, inf});
    f[0][0] = b;
    for (int i = 1; i <= n; i++) {
        if (s[i - 1] == '0') {
            f[i][0] = min({f[i][0], f[i - 1][0] + a + b, f[i - 1][1] + 2 * a + b});
            f[i][1] = min({f[i][1], f[i - 1][0] + 2 * a + 2 * b, f[i - 1][1] + a + 2 * b});
        } else {
            f[i][1] = min(f[i][1], f[i - 1][1] + a + 2 * b);
        }
    }
    cout << f[n][0] << "\n";
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

D. Number Of Permutations

先排序,然后发现连续若干个相同的可以交换位置,因此我们只需按\(a_i,b_i,(a_i,b_i)\)三种分别排序,然后依次求出可以交换出多少情况即可。

然后用容斥原理求一下答案即可。

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int mod = 998244353;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> fact(n + 1);
    fact[0] = 1;
    for (int i = 1; i <= n; i++)
        fact[i] = fact[i - 1] * i % mod;
    vector<pair<int, int>> a(n);

    for (auto &[x, y]: a)
        cin >> x >> y;
    sort(a.begin(), a.end());
    int res = fact[n];

    int ans = 1;
    for (int i = 1, cnt = 1; i < n; i++) {
        if (a[i].first == a[i - 1].first) cnt++;
        else cnt = 1;
        ans = ans * cnt % mod;
    }
    res = (res - ans + mod) % mod;
    ans = 1;
    for (int i = 1; i < n; i++)
        if (a[i].second < a[i - 1].second) ans = 0;
    for (int i = 1, cnt = 1; ans && i <= n; i++) {
        if (a[i] == a[i - 1]) cnt++;
        else cnt = 1;
        ans = ans * cnt % mod;
    }
    res = (res + ans) % mod;
    sort(a.begin(), a.end(), [](pair<int, int> x, pair<int, int> y) {
        return x.second < y.second;
    });

    ans = 1;
    for (int i = 1, cnt = 1; i < n; i++) {
        if (a[i].second == a[i - 1].second) cnt++;
        else cnt = 1;
        ans = ans * cnt % mod;
    }
    res = (res - ans + mod) % mod;
    cout << res << "\n";
    return 0;
}

E. XOR Guessing

先询问高七位都是\(0\),这样可以得到高七位值,在用同样的方法求低七位即可

#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
    cout << "?" << flush;
    for (int i = 1; i <= 100; i++)
        cout << " " << i;
    cout << endl;
    int x;
    cin >> x;

    cout << "?" << flush;
    for (int i = 1; i <= 100; i++ )
        cout << " " << (i<<7);
    cout << endl;
    int y;
    cin >> y;

    int t = (1<<7)-1 , res = 0;
    res |= x & ( t << 7 );
    res |= y & t;
    cout << "! " << res << endl;
    return 0;
}

F. Remainder Problem

分段暴力即可。

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 500005, M = 710;
int a[N] ;
int cnt[M][M];

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int q;
    cin >> q;
    for( int op , x , y ; q ; q -- ){
        cin >> op >> x >> y;
        if( op == 1 ){
            a[x] += y;
            for( int i = 1 ; i < M ; i ++ )
                cnt[i][x%i] += y;
        }else{
            if( x < M )
                cout << cnt[x][y] << "\n";
            else{
                int ans = 0;
                for( int i = y ; i < N ; i += x )
                    ans += a[i];
                cout << ans << "\n";
            }
        }
    }
    return 0;
}

标签:Educational,int,res,ans,Codeforces,long,cin,71,cnt
From: https://www.cnblogs.com/PHarr/p/17578053.html

相关文章

  • Codeforces Round 887 (Div. 1) 题解
    https://codeforces.com/contest/1852/problemsA.Ntarsis'Sethttps://codeforces.com/contest/1852/problem/A感觉不是很一眼。\(n\)和\(k\)都是\(2\times10^5\),不能暴力,设当前集合为\({1,2,\dots,10^{1000}}\),那么被操作过一次的最小值就应该是\(\text{MEX}(0,......
  • CodeForces 1810G The Maximum Prefix
    洛谷传送门CF传送门感觉是比较educational的题。拿到题目应该有一个大致思路,就是考虑最大前缀和的求法,再把它扔到状态里面。最大前缀和有两种求法:从前往后求,需要维护当前前缀和\(s\),当前最大前缀和\(mx\),需要记录两个变量,无法承受。从后往前求,只需记录当前最大前缀和......
  • 「题解」Codeforces Round 887 (Div. 2)
    A.DesortingProblem题目Sol&Code若序列一开始无序答案为\(0\)若有序即\(a_1\leqa_2\leq\dots\leqa_n\)。若想让\(a_i>a_j(i<j)\),操作次数与两数差值\(d(d=a_j-a_i)\)相关为\(\lfloor\dfrac{d}{2}\rfloor+1\),差值越小操作次数越少,故枚举相邻两数取最少......
  • Codeforces Round 887 (Div. 2)
    C.Ntarsis'Set​ (\(1\leqn,k\leq2\cdot10^5\))题解:思维+二分我们不妨反向考虑由于答案最后一次一定在第一个位置所以答案上一轮一定在第一个空的位置,假设这个位置为\(x\)那么如果说要使得答案在位置\(x\),那么上上一轮答案一定在第\(x\)个空的位置我们可以......
  • Codeforces Round 887 (Div 2) C. Ntarsis' Set
    Ntarsis'Set题意是给你n个数,每次按照顺序删除位于a[i]位置的这n个数,问k次后最小的是多少参考这位大佬的题解CodeforcesRound887(Div2)A~C-知乎(zhihu.com)结合一个官方题解,进行一次操作后,由于前面删掉i个数,a[i]到a[i+1]间所有数的排名都要-=i,那么在a[i]到a[i+1]之间的......
  • 【题解】Educational Codeforces Round 151(CF1845)
    VP战报:1h过了A,B,C,D然后被E罚坐1hrank:210th题解只有A-EA.ForbiddenInteger题目描述:你需要构造一个正整数序列,满足:对于\(i\),\(a_i\lek\)且\(a_i\not=x\)。\(\suma_i=n\)。如无法构造,输出NO,否则输出YES后,输出序列长度与序列中的每一个数。多测\(t\le......
  • Codeforces Round 886 (Div. 4) 题解 A - H
    A.ToMyCritics题目大意给定三个数,你可以挑俩数加起来,问这仨数有没有可能加起来大于等于\(10\).解题思路我们找其中最大的两个数相加与\(10\)比较即可。ACCode#include<iostream>#include<algorithm>#include<cstring>#defineendl'\n'#defineiosios::sync......
  • Codeforces Round 886 (Div. 4) 全题题解
    我关注的人中正式参与比赛排名公示:#Who=Penalty*ABCDEFGH1(980)Chen_Jinhui7381\(\color{#00CC00}{\textbf{+}}\)00:05\(\color{#00CC00}{\textbf{+1}}\)00:17\(\color{#00CC00}{\textbf{+}}\)00:19\(\color{#00CC00}{\textbf{+}}\)01:08......
  • Codeforces Round 886 (Div. 4)记录
    A-ToMyCritics代码:#include<cstdio>#include<algorithm>#include<cmath>#include<vector>#include<string.h>#include<set>#include<string>#include<map>#include<iostream>#include<queue>#in......
  • Codeforces Round 885 (Div. 2) A - C
    A.VikaandHerFriendsProblem-A-Codeforces题意:​ 在\(n*m\)的范围内,\(a\)和她的朋友在追逐游戏,每秒\(a\)和朋友必须从当前位置移到相邻的格子里(上下左右),在这一秒结束时\(a\)不能和朋友在同一格内。现在知道\(a\)和每一个朋友的初始位置,问\(a\)是否会被朋友追上。思路:......