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

Codeforces Round 871 (Div. 4) ABCDEF

时间:2023-07-12 18:55:23浏览次数:30  
标签:typedef const int LL cin long 871 Div ABCDEF

很久没写题目了,划点水题

A. Love Story

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7; 
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T = 1;
    cin>>T;
    while (T--)
    {
        string s = "codeforces";
        string c;
        cin >> c;
        LL ans = 0;
        for (int i = 0; i < c.size(); i++)
        {
            if (s[i] != c[i]) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

B. Blank Space

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7; 
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T = 1;
    cin>>T;
    while (T--)
    {
        LL n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
        }
        LL flag = 0;
        LL maxn = 0;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] == 1) flag = 0;
            else flag++;
            maxn = max(maxn, flag);
        }
        cout << maxn << endl;
    }
    return 0;
}

C. Mr. Perfectly Fine

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7; 
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T = 1;
    cin>>T;
    while (T--)
    {
        LL n;
        cin >> n;
        LL minn = MAXN;
        LL ly = MAXN, yl = MAXN;
        for (int i = 1; i <= n; i++)
        {
            LL x, y;
            cin >> x >> y;
            if (y == 11) minn = min(minn, x);
            else if (y == 01) ly = min(ly, x);
            else if (y == 10) yl = min(yl, x);
        }
        minn = min(minn, ly + yl);
        if (minn >= MAXN / 2) minn = -1;
        cout << minn << endl;
    }
    return 0;
}

D. Gold Rush

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7; 
LL a[N];
bool check(LL n, LL m)
{
    queue<LL> q;
    if (n / 3 == m || n / 3 * 2 == m) return true;
    if(n/3>=m)  q.push(n / 3);
    if(n/3*2>=m) q.push(n / 3 * 2);
    while (q.size())
    {
        auto t = q.front();
        q.pop();
        if (t % 3 == 0)
        {
            if (t / 3 == m || t / 3 * 2 == m) return true;
            if (t / 3 >= m)  q.push(t / 3);
            if (t / 3 * 2 >= m) q.push(t / 3 * 2);
        }
    }
    return false;
}
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T = 1;
    cin>>T;
    while (T--)
    {
        LL n, m;
        cin >> n >> m;
        if (n == m) cout << "YES" << endl;
        else if (n < m) cout << "NO" << endl;
        else if (n % 3 != 0) cout << "NO" << endl;
        else {
            if (check(n, m) == true) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    }
    return 0;
}

E. The Lakes

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7; 
LL a[M][M];
bool st[M][M];
LL n, m;
LL dx[] = { -1,0,0,1 }, dy[] = { 0,1,-1,0 };
LL sum = 0, maxn = 0;
void dfs(int x, int y)
{
    st[x][y] = true;
    sum += a[x][y];
    for (int i = 0; i < 4; i++)
    {
        LL xx = dx[i] + x, yy = dy[i] + y;
        if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && st[xx][yy] == false && a[xx][yy] != 0)
        {
            dfs(xx, yy);
        }
    }
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T = 1;
    cin>>T;
    while (T--)
    {
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                cin >> a[i][j];
                st[i][j] = false;
            }
        }
        sum = 0;
        maxn = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                if (st[i][j] == false&&a[i][j]!=0)
                {
                    sum = 0;
                    dfs(i, j);
                    maxn = max(maxn, sum);
                }
            }
        }
        cout << maxn << endl;
    }
    return 0;
}

F. Forever Winter

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7; 
LL n, m;
LL a[N], b[N];
LL d[N], deep[N];
LL maxn = 0;
vector<LL> g[N];
void init()
{
    maxn = 0;
    memset(deep, 0, sizeof deep);
    memset(d, 0, sizeof d);
    for (int i = 0; i <= 1000; i++)
    {
        g[i].clear();
    }
}
void dfs(LL idx, LL depth,LL father)
{
    maxn = max(maxn, depth);
    LL sum = g[idx].size();
    deep[depth]=max(deep[depth],sum);
    for (int i = 0; i < g[idx].size(); i++)
    {
        if (g[idx][i] == father) continue;
        dfs(g[idx][i], depth + 1, idx);
    }
}  
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T = 1;
    cin>>T;
    while (T--)
    {
        cin >> n >> m; 
        init();
        for (int i = 1; i <= m; i++)
        {
            cin >> a[i] >> b[i];
            g[a[i]].push_back(b[i]);
            d[a[i]]++;
            g[b[i]].push_back(a[i]);
            d[b[i]]++;
        }
        LL beg = 0;
        for (int i = 1; i <= m; i++)
        {
            if (d[a[i]] == 1)
            {
                beg = a[i];
                break;
            }
            else if(d[b[i]]==1)
            {
                beg = b[i];
                break;
            }
        }
        dfs(beg, 1,-1); 
        cout << deep[maxn / 2 + 1] << " " << deep[maxn - 1]-1 << endl;
    }
    return 0;
}

标签:typedef,const,int,LL,cin,long,871,Div,ABCDEF
From: https://www.cnblogs.com/Vivian-0918/p/17548552.html

相关文章

  • 「解题报告」Codeforces Round #884 (Div. 1 + Div. 2) Editorial
    比赛地址:Dashboard-CodeforcesRound884(Div.1+Div.2)-Codeforces个人评价:这场是构造专场!A.SubtractionGameProblem-A-Codeforces有一堆石子(应该是石子),每次只能拿走\(a\)块或者\(b\)块,最先不能移动的人输,构造一个数\(n\),使得先手必输。两种构造方法:......
  • UESTC 2023 Summer Training #02 Div.2
    Preface都给我丑完了这怎么办啊,被血虐了苦路西这场本来前面感觉都还可以,但是当中期看了眼C的题意后准备开C后就不对劲了起来最后1h扔掉一直T的C题去做H,结果因为被卡自然溢出的Hash一直挂到比赛结束,直接红温感觉这场策略问题挺大的,比如没有跟榜去写更加简单的E题(比赛的时候题......
  • Codeforces Round #771 (Div. 2) A-E
    A代码#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;intp[507];boolsolve(){intn;cin>>n;for(inti=1;i<=n;i++)cin>>p[i];intpos1=0,pos2=0;for(inti=1;i<=n;i++){......
  • JQuery 控制 Div 显示和隐藏
    页面上有两个Div用JQuery控制Div显示和隐藏。实现Div间切换的需求<divclass="IndConKHuansoverH"id="divExtTelList">11111111111111111111<div><divclass="IndConBflex"id="divExtTelStatus">22222222222222......
  • div小窗的拖动
    最近要做一个置顶聊天框的功能,想着要给他做成可以拖动的一开始使用的是@mousedown+@mousemove+@mouseup来进行小窗口的拖动,但是出现拖动的时候小窗会闪烁,并且位置距离也不好把控,效果不好。然后借鉴了网上大神的帖子,使用v-drage和directives对div进行拖动首先,在控件最外面的div......
  • 从零开始的知识图谱生活,构建一个百科知识图谱,完成基于Deepdive的知识抽取、基于ES的简
    从零开始的知识图谱生活,构建一个百科知识图谱,完成基于Deepdive的知识抽取、基于ES的简单语义搜索、基于REfO的简单KBQA个人入门知识图谱过程中的学习笔记,算是半教程类的,指引初学者对知识图谱的各个任务有一个初步的认识。目前暂无新增计划。1.简介目标是包含百度百科、互动百......
  • Codeforces Round 883 (Div. 3)
    CodeforcesRound883(Div.3)A.RudolphandCuttheRope:题意:有一个糖果由n个绳子悬挂,告诉每一个绳子位于的高度和宽度,问至少间断几根才可以让candy回到groud。思路:统计有几个宽度小于高度的绳子即可voidsolve(){intn;intnum=0;cin>>n;for(inti=1;i......
  • CF div3 883
    题目链接E2按值域分治的技巧前置:\(f(k,n)=1+k+k^2+...+k^n\)\(①\):假设答案最终的\(n=2\),对于\(1+k+k^2\),我们在\([2,10^9]\)的范围二分\(k\)即可\(②\):假设答案最终的\(n>2\),那么形式至少是\(1+k+k^2+k^3......
  • Codeforces Round 875 (Div. 2)(D)
    CodeforcesRound875(Div.2)(D)D(思维)这个题意是给你两个数组,\(a\)和\(b\),我们需要找到这样的二元组\((i,j)\)满足\(a_i\timesa_j=b_i+b_j\),问一共有多少组满足以上条件的二元组题目还告诉我们数组里面的数字都是不大于\(n\)的,那么因为两个数相乘的范围一定是\(1-n\)的,那......
  • CodeTON Round 5 (Div. 1 + Div. 2, Rated, Prizes!) A-E
    比赛链接A代码#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;boolsolve(){intn,m;cin>>n>>m;llsuma=0,sumb=0;for(inti=1,x;i<=n;i++)cin>>x,suma+=x;for(inti=1,......