首页 > 其他分享 >Codeforces Round 957 (Div. 3)

Codeforces Round 957 (Div. 3)

时间:2024-07-16 18:40:18浏览次数:7  
标签:set int Solution cin 957 Codeforces void Div fag

题目链接:Codeforces Round 957 (Div. 3)

总结:E不懂,F差一个set去重

A. Only Pluses

fag:枚举

B. Angry Monk

fag:模拟

Solution:分裂的花费为\(a_i - 1\),添加的花费为\(a_i\)。

C. Gorilla and Permutation

fag:思维

Solution:大于等于\(k\)的数,逆序放在最前面,小于等于\(m\)的数,从最后面开始从大到小放,中间的位置任意放剩下的数。

void solve(){
    cin >> n >> m >> k;
    vector<int> a(n + 1);
    int i, l, r;
    
    for (i = n, l = 1; i >= k; i --, l ++)
        a[l] = i;
    
    for (i = m, r = n; i >= 1; i --, r --)
        a[r] = i;
    
    for (int i = l; i <= r; i ++){
        a[i] = ++ m;
    }
    
    for (int i = 1; i <= n; i ++)
        cout << a[i] << " \n"[i == n];
}

D. Test of Love

fag:DP

Solution:考虑如何从上一步转移,跳过来或者游过来。

  • 注意\(m\)的范围,可以直接枚举前\(m\)个格子(赛时没看到范围,用单调队列优化DP做的)
  • 游过来的前提,上一格是水。
void solve(){
    cin >> n >> m >> k;
    string s;
    cin >> s;
    s = "$" + s;
    deque<int> qu;
    vector<int> f(n + 2, INF);

    f[0] = 0;
    qu.push_back(0);
    for (int i = 1; i <= n + 1; i ++){
        if (s[i] == 'C')
            continue;
        while (qu.size() && qu.front() + m < i){  // 存储原木的坐标
            qu.pop_front();
        }

        if (qu.size())
            f[i] = f[qu.front()];
        if (s[i - 1] == 'W')
            f[i] = min(f[i], f[i - 1] + 1);

        if (s[i] == 'L'){
            while (qu.size() && f[qu.back()] >= f[i])
                qu.pop_back();
            qu.push_back(i);
        }
    }

    if (f[n + 1] > k){
        cout << "NO\n";
    }
    else{
        cout << "YES\n";
    }
}

E. Novice's Mistake

fag:思维

Desription:给定一个\(n\),求出所有满足条件的\(a, b\)组合。

  • \(1 <= a <= 1e4, 1 <= n <= 100\)
  • \(n * a - b\)等于将\(a\)个字符串\(n\)然后删去末尾\(b\)个字符之后代表的整数
  • \(n * a - b > 0\)

Solution:注意到字符串的操作会影响答案的位数,但是数值计算\(n * a\)最多为\(1e6\)所以最大只有\(6\)位。

  • 我们枚举\(a\),然后枚举答案的位数\(k\),对于每个\(k\)求出一个\(b\),判断当前\(a, b\)是否满足条件

Competing:赛场根本没想到位数的关系

void solve(){
    string n;
    cin >> n;
    vector<pii> ans;

    for (int a = 1; a <= 10000; a ++){
        int len = to_string(stoi(n) * a).size();  // 当前位数
        // if (a == 1262)
        //     debug(len);
        for (int k = len; k; k --){
            int b = a * n.size() - k;
            if (!b) 
                continue;
            int t = 0;
            for (int i = 1, j = 0; i <= k; i ++){
                if (j == n.size())
                    j = 0;
                t = t * 10 + (n[j ++] - '0');
            }
            if (t == stoi(n) * a - b){
                ans.push_back({a, b});
            }
            // if (a == 1262 && b == 2519){
            //     debug(t, stoi(n) * a - b);
            // }
        }
    }
    cout << ans.size() << endl;
    for (auto [a, b] : ans){
        cout << a << " " << b << endl;
    }
}

F. Test of Love

fag:思维

Description:有\(n\)个数,给定一个\(x\),将\(n\)个数分为\(k\)个连续区间,每个区间满足任意一个子集的乘积不等于\(x\)。

1 <= n <= 1e5 2 <= x <= 1e5
1 <= a_i <= 2e5

Solution:从前往后模拟当前区间能够得到那些因数(使用set去重),因为因数的个数很少,所以可做

Competing:没考虑到使用\(set\)去重

void solve(){
    int x;
    cin >> n >> x;
    vector<int> a(n);
    set<int> v; // 记录当前区间所有可能出现的x的约数
    for (int i = 0; i < n; i ++)
        cin >> a[i];

    int ans = 1;
    for (int i = 0; i < n; i ++){
        if (x % a[i])
            continue;
        set<int> tmp;
        for (auto j : v){
            tmp.ep(a[i] * j); // 记录能够构造出来的数
        }
        for (auto j : tmp){
            if (x % j)
                continue;
            v.ep(j);
        }
        if (v.find(x) != v.end()){
            ans ++;
            v.clear();
        }
        v.ep(a[i]);
    }
    cout << ans << endl;
}

标签:set,int,Solution,cin,957,Codeforces,void,Div,fag
From: https://www.cnblogs.com/Sakura17/p/18305896

相关文章

  • Codeforces Round 958 (Div. 2)补题
    文章目录A题(拆分多集)B题(获得多数票)C题(固定OR的递增序列)A题(拆分多集) 本题在赛时卡的时间比较久,把这题想复杂了,导致WA了两次。后来看明白之后就是将n每次转换成k-1个1,到最后分不出来k-1个1直接一次就能分完,即结果加一;#include<bits/stdc++.h>#definein......
  • CodeForces 1983A Array Divisibility
    题目链接:CodeForces1983A【ArrayDivisibility】思路    按规律可得,当a[i]=i时满足题目要求。代码#include<functional>#include<iostream>#include<algorithm>#include<queue>#include<stdio.h>#include<string>#include<cstring......
  • CodeForces 1983B Corner Twist
    题目链接:CodeForces1983B【CornerTwist】思路    可以发现操作一次,被操作位置的对应每一横行和每一纵行的加减数都是3,所以可以根据网格a和b的横纵状态确定是否通过操作使得网格a到达网格b。代码#include<bits/stdc++.h>usingnamespacestd;#definelllonglo......
  • CodeForces 1992A Only Pluses
    题目链接:CodeForces1992A【OnlyPluses】思路    代码#include<functional>#include<iostream>#include<algorithm>#include<queue>usingnamespacestd;#definelllonglongconstintN=500+10;inta[N];voidsolve(){intn......
  • CodeForces 1992D Test of Love
    题目链接:CodeForces1992D【TestofLove】思路    从起点开始起跳,找出下一个木头的位置,若与当前位置的距离小于等于m,则可以直接跳过去,否则判断当前位置与下一个木头之间有没有鳄鱼,有鳄鱼则不能到达对岸,否则继续查找下一个木头,直到对岸。代码#include<functional>......
  • CodeForces 1992E Novice's Mistake
    题目链接:CodeForces1992E【Novice'sMistake】思路    直接对a,b枚举肯定会超时,因为a,b数数字过大,但是通过结果a*n-b可以发现结果最多为6位数,所以对结果的位数进行枚举,然后枚举a,来计算出b并判断是否符合题意,同时需要去掉b不符合题目的范围的情况。代码#includ......
  • CodeForces - 1485F
    题目大意给定数组\(b\),求有多少\(a\)数组满足\(a_i=b_i\or\\sum\limits_{k=1}^ia_k=b_i\)。分析既然有前缀和,不妨将前缀和计入状态中,设\(dp_{i,j}\)为前\(i\)个前缀和为\(j\)的方案数。考虑两种条件的转移方程。若选第一种,有\(dp_{i,j}=dp_{i-1,j-b_i}\)若......
  • Codeforces Round #956 (Div. 2) and ByteRace 2024
    目录写在前面ABCDEF写在最后写在前面比赛地址:https://codeforces.com/contest/1983孩子们我回来了。这场实在是太对胃口,vp不到1h就4题了之后EF也口出来了,然而赛时睡大觉去了没打真是亏死。感觉自己的文字能力已经很牛逼了,不需要再多练了,以后的题解都会写得简略些。A......
  • codeforces 1980 E. Permutation of Rows and Columns
    题目链接https://codeforces.com/problemset/problem/1980/E题意共输入\(T\)组测试用例,每组测试用例第一行输入两个整数\(n,m\),分别代表输入的数据的行数和列数,其中\(n*m\leq2*10^5\)。接下来输入两个\(n\)行\(m\)列的矩阵\(a,b\),对于每个矩阵中的元素\(x_{i,j}\)都是......
  • Solution - Codeforces 1311E Construct the Binary Tree
    先去考虑找一下无解条件。首先就是有\(d\)关于\(n\)的下界\(L\),就是弄成一颗完全二叉树的答案。其次有\(d\)关于\(n\)的上界\(R\),就是成一条链的样子。首先当\(d<L\)或\(R<d\)时显然无解。对于\(L\led\leR\)又如何去判定。能发现没有一个比较好的判定......