首页 > 其他分享 >AtCoder Beginner Contest 330

AtCoder Beginner Contest 330

时间:2024-02-04 18:57:05浏览次数:32  
标签:AtCoder Beginner int i32 330 long pair using define

A - Counting Passes

#include <bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;
#define mp make_pair
const int inf = 1e9;


i32 main() {
    int n , l;
    cin >> n >> l;
    int res = 0;
    for( int i = 1 , x ; i <= n ; i ++ )
        cin >> x , res += x >= l;
    cout << res << "\n";
    return 0;
}

B - Minimize Abs 1

#include <bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;
#define mp make_pair
const int inf = 1e9;


i32 main() {
    int n, l, r;
    cin >> n >> l >> r;
    for (int a, i = 1; i <= n; i++) {
        cin >> a;
        if (l <= a and a <= r) cout << a << " ";
        else if( a > r ) cout << r << " ";
        else cout << l << " ";
    }
    cout << "\n";
    return 0;
}

C - Minimize Abs 2

预处理所有的平方数,然后枚举加二分

#include <bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;
#define mp make_pair
const int inf = 1e9, INF = 1e18;


i32 main() {
    int n;
    cin >> n;
    vi a;
    for (int i = 0, x;; i++) {
        x = i * i, a.push_back(x);
        if (x > n) break;
    }
    int res = INF;
    for (int y; const auto &x: a) {
        if (n - x <= 0) res = min(res, x - n);
        else {
            y = lower_bound(a.begin(), a.end(), n - x) - a.begin();
            res = min(res, abs(x + a[y] - n));
            if (y > 1 ) res = min(res, abs(x + a[y - 1] - n));
        }
    }
    cout << res << "\n";
    return 0;
}

D - Counting Ls

直接统计每行每列o的数量,然后枚举一下中心点,计算出两边两个的点的选择方式

#include <bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;
#define mp make_pair
const int inf = 1e9, INF = 1e18;


i32 main() {
    int n;
    cin >> n;
    vector<string> g(n);
    for (auto &i: g) cin >> i;
    vi cntX(n), cntY(n);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            if (g[i][j] == 'x') continue;
            cntX[i]++, cntY[j]++;
        }
    int res = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            if (g[i][j] == 'o') res += (cntX[i] - 1) * (cntY[j] - 1);
        }
    cout << res << "\n";
    return 0;
}

E - Mex and Update

set维护当前序列中哪些数字没有即可,注意的是所有大于n的数字都可以等效为n

#include <bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;
#define mp make_pair
const int inf = 1e9, INF = 1e18;


i32 main() {
    int n, q;
    cin >> n >> q;
    vector<int> cnt(n + 1), a(n);
    for (auto &i: a)
        cin >> i, i = min(i, n), cnt[i]++;
    set<int> mex;
    for (int i = 0; i <= n; i++)
        if (cnt[i] == 0) mex.insert(i);
    for (int i, x; q; q--) {
        cin >> i >> x, i--, x = min(x, n);
        cnt[a[i]]--;
        if (cnt[a[i]] == 0) mex.insert(a[i]);
        cnt[x]++;
        if (cnt[x] == 1) mex.erase(x);
        a[i] = x;
        cout << *mex.begin() << "\n";
    }

    return 0;
}

标签:AtCoder,Beginner,int,i32,330,long,pair,using,define
From: https://www.cnblogs.com/PHarr/p/18006807

相关文章

  • AtCoder Beginner Contest 339
    基本情况A和C出的比较快但不能说秒了还是思考了几分钟的,然后B很奇怪我样例还有一些测试点都能过,但有些测试点就是过不了...A-TLD貌似没啥说的B-Langton'sTakahashi说实话现在还是不懂我的哪里错了很不科学啊,明明很多测试点都过了啊C-PerfectBus做题时的思路:要想求......
  • Japan Registry Services (JPRS) Programming Contest 2024 (AtCoder Beginner Contes
    //这一场我感觉有了新的蜕变思考问题也变了多种,3题(✌)A-TLD思路:题目本意 Youaregivenastring S, Printthelastsubstringwhen S issplitby .s给你一个字符串输出最后的点的网址(类似)的后缀,入坑点没有,题意简单。思路方法:最后一个‘.’为停止符号,倒的字符串......
  • AtCoder Beginner Contest 339
    基本情况ABC秒了,D读错题卡了一段时间,还好爆搜强项,E感觉极其类似LIS,但是似乎又不能用二分DP来写。E感觉极其类似LIS,但是暴力DP肯定T,又知道不能用二分优化事实如此,确实类似LIS,但是通过线段树来维护区间最大值.暂时还没有熟练线段树,先用atc的库来平替.实现上就是将元素依次......
  • Atcoder Beginner Contest 339 解题报告
    AtcoderBeginnerContest339场评:B>C,D>E,F>G,中国选手最擅长的G,集体上分。A-TLDSimulate.strings;voidSolve(){ charc; while(cin>>c) { if(c=='.')s=""; elses+=c; } cout<<s;}B-Langton'sTakahashiSimulat......
  • AtCoder Beginner Contest 339
    A-TLD(abc339A)题目大意给一个网址,问它的后缀是多少。解题思路找到最后的'.'的位置,然后输出后面的字符串即可。python可以一行。神奇的代码print(input().split('.')[-1])B-Langton'sTakahashi(abc339B)题目大意二维网格,上下左右相连,左上原点。初始全部为......
  • AtCoder Beginner Contest 333
    ABC334总结https://atcoder.jp/contests/abc333A-ThreeThrees翻译输入一个正整数\(n\),输出\(n\)遍这个正整数。\(1\len\le9\)。分析没啥好说的,直接输出就好了。code#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;intn;intmain()......
  • E - Revenge of "The Salary of AtCoder Inc."
    E-Revengeof"TheSalaryofAtCoderInc."ProblemStatementAoki,anemployeeatAtCoderInc.,hashissalaryforthismonthdeterminedbyaninteger$N$andasequence$A$oflength$N$asfollows.First,heisgivenan$N$-sideddie(dice)th......
  • AtCoder Beginner Contest 330 ABCDE
    AtCoderBeginnerContest330ABCDEA-CountingPasses签到题,不多说。//AConemoretimes//nndbk#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintmod=1e9+7;constintN=2e5+10;intmain(){ios::sync_with_stdi......
  • AtCoder Beginner Contest 336
    ABC336总结AtCoderBeginnerContest336A-LongLoong翻译给定一个数\(n\),请输出一个由一个L、\(n\)个o、一个n和一个g组成的字符串(区分大小写)。分析按题意模拟即可。code#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=1......
  • AtCoder Beginner Contest 337 D
    AtCoderBeginnerContest337DD-CheatingGomokuNarabe题意:\(W\)列的矩阵,矩阵由o、x、.三种字符组成。你可以进行若干次操作(可以不做),每次操作可以把矩阵中的一个.改成o。请问最少经过多少次操作后,能在矩阵中找到位于同一行或同一列的连续\(K\)个o。思路:这题......