AtCoder Beginner Contest 377

A - Rearranging ABC

字符串有ABC三个字母即可。

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
string s;
cin >> s;
map<char, int> mp;
for (auto t : s) {
mp[t] = 1;
}
if (mp['A'] == 1 && mp['B'] == 1 && mp['C'] == 1) cout << "Yes\n";
else cout << "No\n";
}

B - Avoid Rook Attack

标记一下哪行哪列不可以放,然后暴力枚举

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
char a[10][10];
map<int, int> h, l;
for (int i = 1; i <= 8; i++)
for (int j = 1; j <= 8; j++) {
cin >> a[i][j];
if (a[i][j] == '#') h[i] = 1, l[j] = 1;
}
int cnt = 0;
for (int i = 1; i <= 8; i++) {
for (int j = 1; j <= 8; j++) {
if (a[i][j] == '.') {
if (h[i] == 0 && l[j] == 0) cnt++;
}
}
}
cout << cnt << '\n';
}

C - Avoid Knight Attack

\(set\)套一个\(pair\)将所有能吃的点和有马的点存入\(set\),能放的点就是剩下的点。

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int n, m;
cin >> n >> m;
set<pair<int, int>> se;
int dx[10] = {-1, -2, -2, -1, 1, 2, 2, 1};
int dy[10] = {-2, -1, 1, 2, 2, 1, -1, -2};
while (m--) {
int x, y;
cin >> x >> y;
se.insert({x, y});
for (int i = 0; i < 8; i++) {
if (x + dx[i] >= 1 && x + dx[i] <= n && y + dy[i] >= 1 && y + dy[i] <= n)
se.insert({x + dx[i], y + dy[i]});
}
}
cout << n*n - se.size() << '\n'; }

D - Many Segments 2

首先考虑加法不好做,于是我们选择减法减去所有不合法的区间,那么剩下的就是我们需要的答案。

通过模拟和思考发现我们可以枚举每一个位置 \(i\)查询离这个位置右侧最近的区间左边界\(r\),同时这个区间右边界\(l\)需要大于等于\(i\)此时可以删除(\(i\),\([r,m]\))这些区间组合。

为了实现我们的需求,我们可以对区间按照\(r\)排序,使用双指针查找合法可删除区间。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
struct node {
int l, r;
} a[N];
bool cmp(node x, node y) {
if (x.r != y.r) return x.r < y.r;
return x.l < y.l;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i].l >> a[i].r;
}
sort(a + 1, a + 1 + n, cmp);
int j = 1;
int ans = m + m * (m - 1) / 2;
for (int i = 1; i <= m; i++) {
int x = i;
while (a[j].l < x && j < n) j++;
if (a[j].l < x) ans -= 0;
else ans -= (m - a[j].r + 1);
}
cout << ans << '\n';
}

E - Permute K times 2

TOYOTA SYSTEMS Programming Contest 2024(AtCoder Beginner Contest 377) 补题记录(A-E)的更多相关文章

  1. M-SOLUTIONS Programming Contest 2021(AtCoder Beginner Contest 232) 题解

    目录 G - Modulo Shortest Path H - King's Tour 因为偷懒就只写G和H的题解了. G - Modulo Shortest Path 首先可以观察到对于一条从点\( ...

  2. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  3. atcoder beginner contest 251(D-E)

    Tasks - Panasonic Programming Contest 2022(AtCoder Beginner Contest 251)\ D - At Most 3 (Contestant ...

  4. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  5. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  6. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  7. AtCoder Beginner Contest 255(E-F)

    Aising Programming Contest 2022(AtCoder Beginner Contest 255) - AtCoder E - Lucky Numbers 题意: 给两个数组a ...

  8. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  9. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  10. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

随机推荐

  1. Linux环境变量,知识点汇总

    一.什么是环境变量? 环境变量(environment variables)一般是指在操作系统中用来指定操作系统运行环境的一些参数. 环境变量本质就是一张表,保存在内存当中. 该表在用户登录系统的时候 ...

  2. C++ 中string,wstring,CString常用方法

    一.概念 string和CString均是字符串模板类,string为标准模板类(STL)定义的字符串类,已经纳入C++标准之中.wstring是操作宽字符串的类.C++标准程序库对于string的设 ...

  3. PCIe简介

    PCIe简介 Peripheral Component Interconnect Express (PCI),高速串行计算机扩展总线标准,PCIe对外围设备的组织方式是树形结构. 拓扑结构 根: 树的 ...

  4. 手写一个Promise.all

    Promise.all 特性: 1. 按顺序返回结果数组; 2. 当所有promise完成才返回; 3. 返回第一个报错的promise的信息; 直接上代码: Promise._all = funct ...

  5. 欢迎加入d3shop,一个DDD实战项目

    背景 整个<老肖的领域驱动设计之路>系列关于认知的核心部分已经基本闭环,但纸上得来终觉浅,还是需要通过实际操作来体会和验证我们的观点,接下来,我将通过一个实战项目来带着大家一起体验从需求到 ...

  6. 使用Vue3.5的onWatcherCleanup封装自动cancel的fetch函数

    前言 在欧阳的上一篇 这应该是全网最详细的Vue3.5版本解读文章中有不少同学对Vue3.5新增的onWatcherCleanup有点疑惑,这个新增的API好像和watch API回调的第三个参数on ...

  7. libtool版本错配(libtool version mismatch)

    当使用configure和makefile编译项目时,出现如下报错: libtool: Version mismatch error. This is libtool 2.4.6, but the`` ...

  8. C++中对象的延迟构造

    本文并不讨论"延迟初始化"或者是"懒加载的单例"那样的东西,本文要讨论的是分配某一类型所需的空间后不对类型进行构造(即对象的lifetime没有开始),更通俗点 ...

  9. 多表查询 —— 内连接&外连接&子查询

    连接查询 内连接 1.查询语法 -- 隐式内连接 select 字段列表 from 表1, 表2... where 条件; -- 显式内连接 select 字段列表 from 表1 [INNER] j ...

  10. 某游戏厂商 hdfs 迁移 distcp failing write attempt Tried pipline recovery 5 times without success 问题排查

    报错截图: 从报错信息看是 distcp 起的map 任务在写 hdfs 的 pipline 失败了,并且重试了5次没有成功,所以这个 task 直接抛出错误失败被 kill 了. 先说解决办法: 清 ...