AtCoder Beginner Contest 326 (ABC326)
A. 2UP3DOWN
直接模拟即可。
Code
B. 326-like Numbers
枚举,每次拆除百、十、个位,再判断。
Code
C. Peak
Description
数字线上放置了 \(N\) 个礼物。第 \(i\) 个礼物放置在坐标 \(A_i\) 处。
可以在数轴上选择长度为 \(M\) 的半开区间 \([x,x+M)\),并获得其中包含的所有礼物。
求:最多可以获得多少份礼物?
Solution
二分 / 双指针都可。
二分答案: 二分出最多可以获得多少份礼物,答案为右边界。每次
check,枚举 \([1 \sim n]\),看看 \(a_{i+mid-1} - a_i\) 是否 \(< m\) 即可。双指针: 每次 \(l\) 从 \([1 \sim n]\),用 while 循环枚举的最大右端点,即最大的满足 \(a_r - a_l \le m\) 的点,然后求 \(\max\)。
Code
Solution 1
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int a[N];
int n, m;
map<int, int> mp[N];
set<int> st[N];
int l = 0, r, mid;
bool check(int mid) {
for (int i = 1; i <= n - mid + 1; i++) {
if (a[i + mid - 1] - a[i] < m) return true;
}
return false;
}
int main() {
cin >> n >> m;
r = n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
while (l <= r) {
mid = (l + r) >> 1;
if (check(mid)) l = mid + 1;
else r = mid - 1;
}
cout << l - 1;
return 0;
}
Solution 2
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int a[N];
int main() {
int n, m, ans = 0;
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
int now = 1;
for(int i = 1; i <= n; i++) { // 枚举左指针
while(now < n && a[now + 1] - a[i] < m) now++; // 满足条件就一直自增
ans = max(ans, now - i + 1);
}
cout << ans;
return 0;
}
D. ABC Puzzle
Description
给定两个字符串 \(R\) 和 \(C\) ,分别由 A 、B 和 C 组成。
有一个 \(N \times N\) 网格。
在每个格中,最多只能写 A 、B 和 C 中的一个字符。
确定是否可以满足以下所有条件,如果可以,打印。
每行和每列恰好包含一个
A、一个B和一个C。第 \(i\) 行中最左边的字符与 \(R\) 的第 \(i\) 个字符匹配。
第 \(i\) 列中最上面的字符与 \(C\) 的第 \(i\) 个字符匹配。
Solution
暴力 DFS + 剪枝。
注意一些小优化的细节:
我们可以在 DFS 的过程中,判断目前搜索出来的方案是否合法,如果不合法,直接 return。
不能在搜索完毕之后在判断是否合法,否则时间复杂度极大,可能会被卡。
其他的就是搜索,没什么好说的。
Code
#include <bits/stdc++.h>
using namespace std;
int n, ans[10][10];
bool nowx[10][4], nowy[10][4];
string s, t;
void dfs(int x, int y) {
if (x == n) {
for (int i = 0; i < n; i++)
if (nowx[i][3] + nowx[i][1] + nowx[i][2] + nowy[i][3] + nowy[i][1] + nowy[i][2] != 6) return;
printf("Yes\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
if (!ans[i][j]) putchar('.');
else printf("%c", 'A' - 1 + ans[i][j]);
printf("\n");
}
exit(0);
}
int nx = x, ny = y + 1;
if (ny >= n) nx++, ny = 0;
if (!nowx[x][3] && !nowx[x][1] && !nowx[x][2]) {
if ((nowy[y][3] || nowy[y][1] || nowy[y][2] || s[x] == t[y]) && (!nowy[y][s[x] - 'A' + 1])) {
ans[x][y] = s[x] - 'A' + 1;
nowx[x][s[x] - 'A' + 1] = 1;
nowy[y][s[x] - 'A' + 1] = 1;
dfs(nx, ny);
nowx[x][s[x] - 'A' + 1] = 0;
nowy[y][s[x] - 'A' + 1] = 0;
}
ans[x][y] = 0;
dfs(nx, ny);
} else {
for (int i = 1; i <= 3; i++) {
if ((!nowx[x][i]) && (nowy[y][3] || nowy[y][1] || nowy[y][2] || t[y] - 'A' + 1 == i) && (!nowy[y][i])) {
ans[x][y] = i;
nowx[x][i] = 1;
nowy[y][i] = 1;
dfs(nx, ny);
nowx[x][i] = 0;
nowy[y][i] = 0;
}
}
ans[x][y] = 0;
dfs(nx, ny);
}
}
int main() {
cin >> n >> s >> t;
dfs(0, 0);
printf("No");
return 0;
}
其他的不会,我是菜鸡。
AtCoder Beginner Contest 326 (ABC326)的更多相关文章
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
- AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】
AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...
- AtCoder Beginner Contest 075 C bridge【图论求桥】
AtCoder Beginner Contest 075 C bridge 桥就是指图中这样的边,删除它以后整个图不连通.本题就是求桥个数的裸题. dfn[u]指在dfs中搜索到u节点的次序值,low ...
随机推荐
- Linux 问题:普通用户(non-root)无法ssh登录
vi /etc/pam.d/sshd ## 将下面那行注释,保存文件即可. # Disallow non-root logins when /etc/nologin exists. account r ...
- VSCode:缩进两格空格
在设定中对如图所示两项进行修改: 至此问题解决.
- Django: You are trying to add a non-nullable field 'name' to mainnav without a default; we can't do that (the database needs something to populate existing rows).
错误原因: 语句中缺少默认值 class Main(models.Model): img = models.CharField(max_length=255) name = models.CharFi ...
- 【必看!】阿里云推出QWen-7B和QWen-7b-Chat,开放免费商用!
阿里云于8月3日宣布开源两款重要的大型模型--QWen-7B和QWen-7b-Chat.这两款模型的参数规模达到了令人瞩目的70亿,并且已经在Hugging Face和ModelScope平台上开放, ...
- MIT6.s081/6.828 lectrue4:page tables 以及 Lab3 心得
不管是计算机组成还是操作系统,虚拟内存都是其中的重要内容,所以这一节我会结合 CSAPP 第九章:虚拟内存 来一起复习(顺便一说,CSAPP 这一节的 lab 是要求设计一个内存分配器,也是很有意思的 ...
- 微服务架构|go-zero 的自适应熔断器
原文链接: go-zero 的自适应熔断器 上篇文章我们介绍了微服务的限流,详细分析了计数器限流和令牌桶限流算法,这篇文章来说说熔断. 熔断和限流还不太一样,限流是控制请求速率,只要还能承受,那么都会 ...
- .NET 8 Release Candidate 1 (RC1)现已发布,包括许多针对ASP.NET Core的重要改进!
这是我们计划在今年晚些时候发布的最终.NET 8版本之前的两个候选版本中的第一个.大部分计划中的功能和变更都包含在这个候选版本中,可以供您尝试使用.您可以在文档中找到完整的ASP.NET Core在. ...
- 开源通用型流式大数据统计系统XL-LightHouse介绍
概述 XL-LightHouse是针对互联网领域繁杂的流式数据统计需求而开发的一套集成了数据写入.数据运算.数据存储和数据可视化等一系列功能,支持大数据量,支持高并发的[通用型流式大数据统计平台]: ...
- MySQL-通过存储过程来添加和删除分区(List分区)
1.背景原因 当前MySQL不支持在添加和删除分区时,使用IF NOT EXISTS和IF EXISTS.所以在执行调度任务时,直接通过ADD PARTITION和DROP PARTITION不可避免 ...
- mysql触发器使用教程-六种触发器
参考:https://zhuanlan.zhihu.com/p/439273702 触发器(Trigger)是 MySQL 中非常实用的一个功能,它可以在操作者对表进行「增删改」 之前(或之后)被触发 ...