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\) ,分别由 ABC 组成。

有一个 \(N \times N\) 网格。

在每个格中,最多只能写 ABC 中的一个字符。

确定是否可以满足以下所有条件,如果可以,打印。

  • 每行和每列恰好包含一个 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)的更多相关文章

  1. AtCoder Beginner Contest 100 2018/06/16

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

  2. AtCoder Beginner Contest 052

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

  3. AtCoder Beginner Contest 053 ABCD题

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

  4. AtCoder Beginner Contest 136

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

  5. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  6. AtCoder Beginner Contest 076

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

  7. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  8. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  9. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】

    AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...

  10. AtCoder Beginner Contest 075 C bridge【图论求桥】

    AtCoder Beginner Contest 075 C bridge 桥就是指图中这样的边,删除它以后整个图不连通.本题就是求桥个数的裸题. dfn[u]指在dfs中搜索到u节点的次序值,low ...

随机推荐

  1. Centos静默安装Oracle11G

    环境准备 Oracle 11gR2 64位 Linux版安装包 linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip ...

  2. Windows安装SSH服务器

    1.打开Win的设置并在设置中找到应用 2.在应用中依次选择应用和功能 可选功能 3.在可选功能中选择添加功能 (OpenSSH客户端默认已存在) 选中OpenSSH服务器后点击下方的安装 4.快捷键 ...

  3. pandas取出包含某个值的所有行

    pandas取出包含某个值的所有行df = df[df["from_account"].str.contains("fcwhx")] pandas取出不包含某个 ...

  4. python2.7源码安装方式

    安装python2.7 下载Python 2.7, 下载地址 解压安装 tar -xzvf Python-2.7.15.tgz cd Python-2.7.15 ./configure --prefi ...

  5. 修复grub分区

    修复grub分区 实验环境:grup.cfg文件丢失,引导出错 1,删除grup.cfg配置文件 2,重启虚拟机 3,重启进入救援模式 再读进度条的时候快速点击Esc键 选着光驱或者u盘启动  

  6. 可实现自动驾驶的飞机大战(C++)

    PS:觉得可以的uu帮忙点个star啦,最近在找工作,希望star多一点能写到简历上 B站演示视频: 基于C++实现的可自动驾驶的飞机大战_单机游戏热门视频 (bilibili.com) Github ...

  7. BUUCTF-RE-[BJDCTF2020]BJD hamburger competition

    啊这,点进去康康 dnspy反编译的题,https://www.52pojie.cn/thread-495115-1-1.html 里面有详细介绍 然后文件很多,我不知道找哪一个下手 看其他师傅的wp ...

  8. 《Kali渗透基础》14. 无线渗透(四)

    @ 目录 1:相关工具 1.1:Aircrack-ng 1.1.1:airmon-ng 1.1.2:airodump-ng 1.1.3:aireplay-ng 1.1.4:airolib-ng 1.1 ...

  9. H.265+SRS6.0服务器部署

    H.265+SRS6.0服务器部署 SRS从6.0开始,全面支持H.265,包括RTMP.FLV.HLS.GB28181.WebRTC等等.具体的服务器部署及H.265推流步骤如下. 1. SRS 要 ...

  10. crontab定时任务不执行的一些原因总结

    参考博文地址: https://www.jb51.net/article/154290.htm声明:本文章是在以上地址博文基础上进行整理学习,如有侵权,请联系博主删除,感谢知识共享,一起进步,加油鸭 ...