HHKB Programming Contest 2020【ABCE】
比赛链接:https://atcoder.jp/contests/hhkb2020/tasks
A - Keyboard
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
char s, t;
cin >> s >> t;
cout << (s == 'Y' ? char(toupper(t)) : t) << "\n";
return 0;
}
B - Futon
题解
每个点只考虑右方和下方的点即可。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w;
cin >> h >> w;
vector<string> MP(h);
for (auto &x : MP) cin >> x;
int ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (MP[i][j] == '.' and i + 1 < h and MP[i + 1][j] == '.') ++ans;
if (MP[i][j] == '.' and j + 1 < w and MP[i][j + 1] == '.') ++ans;
}
}
cout << ans << "\n";
return 0;
}
C - Neq Min
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
set<int> st;
for (int i = 0; i <= 200010; i++)
st.insert(i);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
st.erase(x);
cout << *st.begin() << "\n";
}
return 0;
}
E - Lamps
题解
假设每盏灯在所有情况中都亮着,则亮着的灯的总数为 \(k \cdot 2^k\) 。
考虑每盏灯不亮的情况有多少种:一盏灯不亮的充要条件是上下左右连通的灯都不亮,设这些灯加上自身总个数为 \(tot\),那么其余的 \(k-tot\) 盏灯的亮灭情况是随意的,即 \(2^{(k - tot)}\) 。
答案即为 $k \cdot 2^k - \sum \limits _{i = 1}^k 2^{(k - tot_i)} $ 。
上下左右连通的灯数用前缀和计算一下即可。
代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int N = 2020;
constexpr int MOD = 1e9 + 7;
char MP[N][N];
int up[N][N];
int dn[N][N];
int lf[N][N];
int rt[N][N];
int k;
int binpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = 1LL * res * a % MOD;
a = 1LL * a * a % MOD;
b >>= 1;
}
return res;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w;
cin >> h >> w;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> MP[i][j];
if (MP[i][j] == '.') ++k;
}
}
for (int j = 1; j <= w; j++) {
for (int i = 1; i <= h; i++) {
if (MP[i][j] == '#') {
up[i][j] = 0;
} else {
up[i][j] = up[i - 1][j] + 1;
}
}
}
for (int j = 1; j <= w; j++) {
for (int i = h; i >= 1; i--) {
if (MP[i][j] == '#') {
dn[i][j] = 0;
} else {
dn[i][j] = dn[i + 1][j] + 1;
}
}
}
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (MP[i][j] == '#') {
lf[i][j] = 0;
} else {
lf[i][j] = lf[i][j - 1] + 1;
}
}
}
for (int i = 1; i <= h; i++) {
for (int j = w; j >= 1; j--) {
if (MP[i][j] == '#') {
rt[i][j] = 0;
} else {
rt[i][j] = rt[i][j + 1] + 1;
}
}
}
int ans = k * binpow(2, k);
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (MP[i][j] == '.') {
int tot = up[i][j] + dn[i][j] + lf[i][j] + rt[i][j] - 4 + 1;
ans -= binpow(2, k - tot);
(ans += MOD) %= MOD;
}
}
}
cout << ans << "\n";
return 0;
}
HHKB Programming Contest 2020【ABCE】的更多相关文章
- HHKB Programming Contest 2020 D - Squares 题解(思维)
题目链接 题目大意 给你一个边长为n的正方形和边长为a和b的正方形,要求把边长为a和b的正方形放在长度为n的正方形内,且没有覆盖(可以相邻)求有多少种放法(mod 1e9+7) 题目思路 这个思路不是 ...
- M-SOLUTIONS Programming Contest 2020 题解
M-SOLUTIONS Programming Contest 2020 题解 目录 M-SOLUTIONS Programming Contest 2020 题解 A - Kyu in AtCode ...
- 2021.7.27--Benelux Algorithm Programming Contest 2020 补提
I Jigsaw 题目内容: 链接:https://ac.nowcoder.com/acm/contest/18454/I 来源:牛客网 You have found an old jigsaw pu ...
- POJ 3660 Cow Contest. (传递闭包)【Floyd】
<题目链接> 题目大意: 有n头牛, 给你m对关系(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少牛的排名. 解题分析: 首先,做这道题要明确,什么叫确定牛的排名.假设 ...
- atcoder Keyence Programming Contest 2020 题解
比赛地址 A 题意:给一个\(n*m\)的初始为白色的矩阵,一次操作可以将一行或一列染成 黑色,问至少染出\(k\)个黑点的最少操作次数. \(n\),\(m\)<=100,\(k\)<= ...
- luogu P1452 [USACO03FALL]Beauty Contest G /【模板】旋转卡壳
LINK:旋转卡壳 如题 是一道模板题. 容易想到n^2暴力 当然也能随机化选点 (还真有人过了 考虑旋转卡壳 其实就是对于某个点来说找到其最远的点. 在找的过程中需要借助一下个点的帮助 利用当前点到 ...
- Social Infrastructure Information Systems Division, Hitachi Programming Contest 2020 D题题解
将题意转换为一开始\(t = 0\),第\(i\)个操作是令\(t \leftarrow (a_i + 1) t + (a_i + b_i + 1)\).记\(A_i = a_i + 1, B_i = ...
- Social Infrastructure Information Systems Division, Hitachi Programming Contest 2020 C题题解
首先,我们将题目理解成若\(i\)与\(j\)距离恰好为\(3\),则不可能\(p_i \equiv p_j \equiv 1 \space or \space 2 (\bmod 3)\).这就相当于 ...
- Atcoder Panasonic Programming Contest 2020
前三题随便写,D题是一道dfs的水题,但当时没有找到规律,直接卡到结束 A - Kth Term / Time Limit: 2 sec / Memory Limit: 1024 MB Score ...
随机推荐
- Linux复制某个目录下结构
Linux复制某个目录下结构 结合tree命令把当前目录下的文件夹路径存储到document.txt文件,然后再使用mkdir命令把document.txt文件下的目录输入创建: tree -fid ...
- Python列表推导式玩法
前言 列表做为python的基础,是必须学习的语法之一.一些基础的之前已经是反复温习和使用了,今天我们来学习它的进阶版-->列表推导式. 列表推导式: 优点:是将所有的值一次性加载到内存中,相比 ...
- 【Linux】在docker上部署grafana+zabbix监控实录
------------------------------------------------------------------------------------------------- ...
- 基础练习(上) - 蓝桥杯(Python实现)
闰年判断: 题目: 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 给定一个年份,判断这一年是不是闰年. 当以下情况之一满足时,这一年是闰年: 1. 年份是4的倍数而不是100的倍数 ...
- 人工智能"眼睛"——摄像头
摄像头机器视觉人工智能的"眼睛",其重要性在嵌入式领域不言而喻.但是如何理解和使用摄像头却是一个非常棘手的问题.本文主要针对调试摄像头过程中遇到的问题,对摄像头的基本原理及概述进行 ...
- 六个你不知道的PR快捷键,拯救你的剪辑效率
5G时代到来,会剪辑视频的人,无论在校园还是未来步入职场都很吃香.对于普通人来说,视频处理也成为了一个通用技能.PR是我们大多数人剪辑中,经常会用到的剪辑工具,之前的文章中已经给大家总结了pr的一些提 ...
- C# socket 阻止模式与非阻止模式应用实例
问题概述 最近在处理一些TCP客户端的项目,服务端是C语言开发的socket. 实际项目开始的时候使用默认的阻塞模式并未发现异常.代码如下 1 public class SocketService 2 ...
- 使用Gulp里面的浏览器同步插件browser-sync的注意事项
使用Gulp里面的浏览器同步插件browser-sync的注意事项 第一步:打开你的开发者工具, 编写前端代码!图如下! 第二步:打开你当前工作目录的命令行窗口 第三步:输入浏览器同步执行的代码! b ...
- 1、剑指offer-数组——二维数组中的查找
*题目描述* **在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含 ...
- 406 UDP协议是面向非连接的协议 Keep-Alive
HTTP The Definitive Guide Table 3-1. Common HTTP methods Method Description Message body? GET ...