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

AtCoder Beginner Contest 124

时间:2024-05-28 20:34:10浏览次数:27  
标签:AtCoder cnt Beginner int res cin vector 124 using

A - Buttons

#include <bits/stdc++.h>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int res = 0;
	if(a > b) res += a, a --;
	else res += b, b --;

	if(a > b) res += a, a --;
	else res += b, b --;
	cout << res << "\n";	
	return 0;
}

B - Great Ocean View

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

int main() {
	int n;
	cin >> n;
	vi h(n);
	for(auto &i : h) cin >> i;
	int res = 1, pre = h[0];
	for(int i = 1; i < n; i ++){
		res += (h[i] >= pre);
		pre = max(pre, h[i]);
	}
	cout << res << "\n";
	return 0;
}

C - Coloring Colorfully

动态规划

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	s = " " + s;
	vector<array<int,2>> f(n + 1);
	for(int i = 1, x; i <= n ; i ++) {
		x = s[i] - '0';
		f[i][x] = f[i-1][x ^ 1];
		f[i][x ^ 1] = f[i-1][x] + 1;
	}
	cout << min(f[n][0], f[n][1]);
	return 0;
}

D - Handstand

双指针

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

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

    string s;
    cin >> s;
    s += '.';

    vector<int> a, b;
    for (int i = 1, cnt = 1; i < s.size(); i++) {
        if (s[i] == s[i - 1]) cnt++;
        else {
            a.push_back(cnt);
            b.push_back(s[i - 1] - '0');
            cnt = 1;
        }
    }
    int m = a.size();
    int res = 0;
    for (int l = 0, r = -1, cnt = 0, len = 0; l < m; l++) {
        while (r + 1 < m and cnt + (b[r + 1] == 0) <= k)
            r++, cnt += (b[r] == 0), len += a[r];
        res = max(res, len);
        cnt -= (b[l] == 0), len -= a[l];
    }
    cout << res << "\n";
    return 0;
}

标签:AtCoder,cnt,Beginner,int,res,cin,vector,124,using
From: https://www.cnblogs.com/PHarr/p/18218791

相关文章

  • AtCoder abc325D
    原题链接ProblemStatementThereare\(N\)productslabeled\(1\)to\(N\)flowingonaconveyorbelt.AKeyenceprinterisattachedtotheconveyorbelt,andproduct\(i\)enterstherangeoftheprinter\(T_i\)microsecondsfromnowandleavesit......
  • AtCoder Beginner Contest 355(F - MST Query)
    很久没有见到这么好的题了。原题面用ChatGPT......
  • Tokio Marine & Nichido Fire Insurance Programming Contest 2024(AtCoder Beginner C
    A-WhoAtetheCake?题意:有三个嫌疑犯(1,2,3(号码))现在有两个证人他们指出谁不是嫌疑犯,你可以找到确定的那个罪人吗?找到输出这个人的号码没找到输出-1思路:如果两人指出的人是一个人则输出-1不是则输出6-a-b,因为1+2+3=6(sum)减去a,b肯定可以到达......
  • D - AtCoder Wallpaper(求图形面积)
    思路:求f(c,d)+f(a,b)-f(a,d)-f(c,b);代码:intf(intx,inty){if(y%2==0){y=y/2;intans=y*(x/4)*8;x%=4;if(x==1){ans+=y*3;}elseif(x==2){ans+=y*6......
  • Atcoder 题目选做(五)
    \(\text{ByDaiRuiChen007}\)1.[ARC159E]DifferenceSumQueryProblemLink给定\(n,m\),定义\(x\in[1,n]\)的深度\(f(x)\)为:初始\([l,r]=[1,n]\)。第\(i\)次操作求出\(l,r\)按\(a_{i\bmodm}:b_{i\bmodm}\)的比例的中点\(mid\)。如果\(x=mid\),那么......
  • Atcoder 题目选做(六)
    \(\text{ByDaiRuiChen007}\)1.[ARC162E]StrangeConstraintsProblemLink给定\(a_1\sima_n\),求有多少\(b_1\simb_n\)满足:\(b_i\in[1,n]\),且\(i\)和\(b_i\)的出现次数均不超过\(a_i\)。数据范围:\(n\le500\)。设\(\gek\)的\(a_i\)有\(c_k......
  • Atcoder 题目选做(四)
    \(\text{ByDaiRuiChen007}\)1.[AGC059C]GuessingPermutationforasLongasPossibleProblemLink给定\(\dfrac{n\times(n-1)}2\)个\([1,n]\)中的二元对的顺序,求有多少个\(n\)阶排列\(P\)使得按顺序询问到每个\((u,v)\)之前无法确定\(P_u,P_v\)大小关系......
  • ABC 354 (atcoder beginer 354) D、E、F
     D 检查:1.有可能是推导式有问题,比如-/+写错2.x,yA、B、C、D顺序可能搞反了不要盲目调试,先用人眼看一下代码的情况,找一下错误 很简单的找规律的题目。很不能理解过的人,就这些。x方向,y方向,都是4行/列,一个规律的循环。 求(0,0)到(x,y)中的黑色块:第0-3行分别求出黑色......
  • Godot Breakeys Godot Beginner Tutorial 游戏开发笔记
    目录前言资源下载添加人物节点运动状态机移动平台单向穿过奇怪的BugArea2DBodyEntered死亡区域全局类多线程安全TileMap处理TileMap分层前言这次来学习一下youtube的传奇Unity博主,Breakeys的Godot新手教程。Breakeys是从15岁左右就开始用unity做游戏并在youtube上面发布视频了。......
  • AtCoder abc354E
    原题链接ProblemStatementTakahashiandAokiareplayingagameusing\(N\)cards.Thefrontsideofthe\(i\)-thcardhas\(A_i\)writtenonit,andthebacksidehas\(B_i\)writtenonit.Initially,the\(N\)cardsarelaidoutonthetable.Wit......