首页 > 其他分享 >Codeforces Round 898 (Div. 4)

Codeforces Round 898 (Div. 4)

时间:2023-09-22 14:00:12浏览次数:41  
标签:10 const 898 Codeforces long int using Div define

Codeforces Round 898 (Div. 4)

A. Short Sort

解题思路:

遍历所有交换情况,看是否有\(abc\).

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const int M = 2 * M;
typedef pair<int, int> pii;
#define fi first
#define se second
int n, m, k;
void solve()
{
    string s;
    cin >> s;
    string a = s;
    swap(a[0], a[1]);
    string b = s;
    swap(b[0], b[2]);
    string c = s;
    swap(c[1], c[2]);
    string t = "abc";
    if (s == t || a == t || b == t || c == t)
    {
        puts("YES");
    }
    else
    {
        puts("NO");
    }
}

int main()
{
    int t = 1;
    scanf("%d", &t);
    while (t--)
    {
        solve();
    }
    return 0;
}

B. Good Kid

解题思路:

将最小的数字加一.

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const int M = 2 * M;
typedef pair<int, int> pii;
#define fi first
#define se second
int n, m, k;
void solve()
{
    scanf("%d", &n);
    vector<int> a(n + 1);
    int idx = 0;
    int res = 12312;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        if (a[i] < res)
        {
            res = a[i];
            idx = i;
        }
    }
    a[idx]++;
    ll ans = 1;
    for (int i = 1; i <= n; i++)
    {
        ans *= (ll)a[i];
    }
    printf("%lld\n", ans);
}

int main()
{
    int t = 1;
    scanf("%d", &t);
    while (t--)
    {
        solve();
    }
    return 0;
}

C. Target Practice

解题思路:

由于图是固定的,暴力判断每个击中的点属于哪一类即可。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const int M = 2 * M;
typedef pair<int, int> pii;
#define fi first
#define se second
int n, m, k;
char g[100][100];
void solve()
{
    for (int i = 1; i <= 10; i++)
    {
        scanf("%s", g[i] + 1);
    }
    n = 10;
    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (g[i][j] == 'X')
            {
                if (i == 1 || i == 10)
                {
                    ans += 1;
                }
                else if (i == 2 || i == 9)
                {
                    if (j == 1 || j == 10)
                    {
                        ans += 1;
                    }
                    else
                    {
                        ans += 2;
                    }
                }
                else if (i == 3 || i == 8)
                {
                    if (j == 1 || j == 10)
                    {
                        ans += 1;
                    }
                    else if (j == 2 || j == 9)
                    {
                        ans += 2;
                    }
                    else
                    {
                        ans += 3;
                    }
                }
                else if (i == 4 || i == 7)
                {
                    if (j == 1 || j == 10)
                    {
                        ans += 1;
                    }
                    else if (j == 2 || j == 9)
                    {
                        ans += 2;
                    }
                    else if (j == 3 || j == 8)
                    {
                        ans += 3;
                    }
                    else
                    {
                        ans += 4;
                    }
                }
                else if (i == 5 || i == 6)
                {
                    if (j == 1 || j == 10)
                    {
                        ans += 1;
                    }
                    else if (j == 2 || j == 9)
                    {
                        ans += 2;
                    }
                    else if (j == 3 || j == 8)
                    {
                        ans += 3;
                    }
                    else if (j == 4 || j == 7)
                    {
                        ans += 4;
                    }
                    else
                    {
                        ans += 5;
                    }
                }
            }
        }
    }
    printf("%lld\n", ans);
}

int main()
{
    int t = 1;
    scanf("%d", &t);
    while (t--)
    {
        solve();
    }
    return 0;
}

D. 1D Eraser

解题思路:

从左往右遍历,遇到一个\(B\)就以他为起点向右染白即可。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const int M = 2 * M;
typedef pair<int, int> pii;
#define fi first
#define se second
int n, m, k;

void solve()
{
    scanf("%d %d", &n, &k);
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'B')
        {
            cnt++;
            int j = 0;
            for (j = i; j <= i + k - 1; j++)
            {
                s[i] = 'W';
            }
            j--;
            i = j;
        }
    }
    printf("%d\n", cnt);
}

int main()
{
    int t = 1;
    scanf("%d", &t);
    while (t--)
    {
        solve();
    }
    return 0;
}

E. Building an Aquarium

解题思路:

二分高度,暴力判断。

注意本题二分边界,最小取到1。

由于答案上界为\(2\times 10^9\),\(n = 1,a[1] = 10^9,x = 10^9\)。

右边界也别取太大,如\(10^{18}\),二分过程会爆\(long \ long\)。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const int M = 2 * M;
typedef pair<int, int> pii;
#define fi first
#define se second
int n, m, k;

void solve()
{
    scanf("%d %d", &n, &k);
    vector<ll> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
    }
    ll l = 1;
    ll r = 3e9;
    auto check = [&](ll h)
    {
        ll sum = 0;
        for (int i = 1; i <= n; i++)
        {
            sum += max(0ll, h - a[i]);
        }
        if (sum > k)
        {
            return false;
        }
        else
        {
            return true;
        }
    };
    while (l + 1 < r)
    {
        ll mid = l + r >> 1;
        if (check(mid))
        {
            l = mid;
        }
        else
        {
            r = mid;
        }
    }
    printf("%lld\n", l);
}

int main()
{
    int t = 1;
    scanf("%d", &t);
    while (t--)
    {
        solve();
    }
    return 0;
}

F. Money Trees

解题思路:

类似滑动窗口。

从左往右遍历,在线记录以\(i\)为最后一个元素,向左最长可以选择多少元素。

用前缀和计算当前最大区间和。

若区间和大于限制,那么从左端点开始一个个删去,直至区间和合法。此时区间长度就是以第\(i\)个元素为结尾的最长区间。

全局答案就是所有最长区间中的最大值。

注意:左右端点可以相等。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const int M = 2 * M;
typedef pair<int, int> pii;
#define fi first
#define se second
int n, m, k;

void solve()
{
    scanf("%d %d", &n, &k);
    vector<int> a(n + 1), h(n + 1), b(n + 1);
    vector<ll> s(n + 1);
    vector<pii> v;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        s[i] = a[i] + s[i - 1];
    }
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &h[i]);
    }
    ll ans = 0;
    int idx = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i == 1)
        {
            b[i] = 0;
        }
        else if (h[i - 1] % h[i] == 0)
        {
            b[i] = b[i - 1] + 1;
        }
        else
        {
            b[i] = 0;
            // continue;
        }
        int l = max(i - b[i], idx);
        int r = i;
        ll res = s[r] - s[l - 1];
        if (res <= k)
        {
            // cout << i << ' ' << (r - l + 1) << endl;
            ans = max(ans, r - l + 1ll);
        }
        else
        {
            while (res > k)
            {
                res -= a[l];
                l++;
            }
            idx = l;
            ans = max(ans, r - l + 1ll);
        }
    }
    printf("%lld\n", ans);
}

int main()
{
    int t = 1;
    scanf("%d", &t);
    while (t--)
    {
        solve();
    }
    return 0;
}

G .ABBC or BACB

解题思路:

我们可以将连续的\(A\)看成\(A\)块。

我们发现,一个\(B\)无论在\(A\)块的左边还是右边,都可以对整个\(A\)块进行连续操作,此时对答案的贡献就是块中\(A\)的个数\(res\)。

所以,我们统计\(A\)块的数量\(cnt_a\),同时统计与\(A\)块相邻的\(B\)的数量\(cnt_b\)。

如果\(cnt_b >= cnt_a\),那么答案就是\(res\).

否则,答案就是\(res-最小的A块中的A的数量\)。因为\(A\)块就是由\(B\)分割而来,\(min(cnt_b) = cnt_a - 1\)。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const int M = 2 * M;
typedef pair<int, int> pii;
#define fi first
#define se second
int n, m, k;

void solve()
{
    string s;
    cin >> s;
    n = s.size();
    s = ' ' + s;
    int ans = 0;
    int cnt = 0;
    int res = 0;
    vector<int> v;
    for (int i = 1; i <= n; i++)
    {
        char c = s[i];
        if (c == 'A')
        {
            cnt++;
        }
        else
        {
            if (s[i - 1] == 'A' || s[i + 1] == 'A')
            {
                res++;
            }
            if (cnt)
            {
                v.push_back(cnt);
                ans += cnt;
            }
            cnt = 0;
        }
    }
    if (cnt)
    {
        v.push_back(cnt);
        ans += cnt;
    }
    sort(v.begin(), v.end());
    if (res < v.size())
    {
        if (!v.empty())
        {
            ans -= v[0];
        }
    }
    printf("%d\n", ans);
}

int main()
{
    int t = 1;
    scanf("%d", &t);
    while (t--)
    {
        solve();
    }
    return 0;
}

标签:10,const,898,Codeforces,long,int,using,Div,define
From: https://www.cnblogs.com/value0/p/17722172.html

相关文章

  • CodeTON Round 6 (Div. 1 + Div. 2, Rated, Prizes!)
    Preface这场因为晚上去做大物实验了,到寝室洗完澡都11点了,就没现场打了的说后面补题发现前5题都很一眼,虽然补题的时候E题FST了(T在了42个点,如果放在比赛就FST了),F题还是很有意思的一个题目的说A.MEXanizedArray简单讨论一下即可#include<cstdio>#include<iostream>#include......
  • Educational Codeforces Round 123 - D(思维题)
    目录D.CrossColoringD.CrossColoring题意$n\timesm$的方格纸上进行q次操作,每次操作选择某整行x和某整列y,使得行x和列y均涂上k种颜色中的一种。问你最终的方案数思路倒序考虑操作,因为对于同一行或者同一列,后面的操作覆盖前面的操作利用数组标记某行或者某......
  • 题解 ARC141D【Non-divisible Set】
    这个题不是网络流。problem我们说一个集合\(D\)是一个好的集合,当不存在集合中的两个不同元素\(a,b\)使得\(a\)是\(b\)的约数。给定\(N\)个整数的一个集合\(S\),值域均落在\([1,2*M]\)内。对\(S\)中的每个元素\(A_i\)询问:是否存在一个恰好包含\(A_i\)的\(......
  • selenium 报错 element not interactable: [object HTMLDivElement] has no size and
    selenium自动化识别验证码x,y坐标 命令move_to_element_with_offset报错:elementnotinteractable:[objectHTMLDivElement]hasnosizeandlocation由于>4.0是以中心点偏移,4.0是左上角偏移。卸载掉最新的seleniuim:pipuninstallselenium安装selenium4.0:pipinstalls......
  • CodeTON Round 6 (Div. 1 + Div. 2, Rated, Prizes!) 更新ing
    A.MEXanizedArray题意给你三个数\(n\)、\(k\)、\(x\),让你求出能否构造出mex为\(k\),且所有数字都不超过\(x\),大小为\(n\)的数组。线索1如果有存在-1情况,先想啥时候不可能,如果能一下子找到-1的情况,这个题会很简单,因为可以的情况反推过去很容易,如果特判复杂就想想是不是诈骗规......
  • 在开启contenteditable可编辑div光标处插入图片
     $("#Content").focus();//创建img元素varimg=document.createElement('img');img.src='xxxx';img.style.display='block';//插入img元素if(window.getSelection){vareditableDiv=document.getEle......
  • <div>标签
    1.盒子模型(上右下左顺时针顺序设置属性值)1.1外边距margin1.2内边距padding1.3边框bordersoliddashed例如:(border:1pxdashedblack)意思就是设置1个像素的黑色虚线边框1.4阴影box-shadow:h-shadow水平阴影的位置  v-shadow垂直阴影的位置  blur模糊距离  sprea......
  • div 拖动例子
    第一个是简单的例子:<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html> <head> <title>dragTest</title> <metahttp-equiv="content-type"content="text/html;charset=UTF-8"> <......
  • Educational Codeforces Round 154 (Rated for Div. 2) A-D
    传送门:edu154/div2A.PrimeDeletion题意:给定一个0-9的排列,要求一个长度>=2的子序列,使得该子序列是质数做法:考虑31或者13即可。不过当时没有立刻想到,感觉1000以内的质数必有答案,打了暴力。用时就多了点。Code#include<bits/stdc++.h>usingnamespacestd;intpri[10......
  • CF1870 div1+div2做题记录
    A题面挺蠢的,无解条件为\(n<k\)或\(x<k-1\),即\(\mathop{\mathrm{mex}}\not=k\)。先选\(0\simk-1\),再选能选的最大值,当\(x=k\),选\(x-1\),否则选\(x\)。点击查看代码#include<bits/stdc++.h>#defineullunsignedlonglong#definelllonglong#definepiipai......