比赛链接: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】的更多相关文章

  1. HHKB Programming Contest 2020 D - Squares 题解(思维)

    题目链接 题目大意 给你一个边长为n的正方形和边长为a和b的正方形,要求把边长为a和b的正方形放在长度为n的正方形内,且没有覆盖(可以相邻)求有多少种放法(mod 1e9+7) 题目思路 这个思路不是 ...

  2. M-SOLUTIONS Programming Contest 2020 题解

    M-SOLUTIONS Programming Contest 2020 题解 目录 M-SOLUTIONS Programming Contest 2020 题解 A - Kyu in AtCode ...

  3. 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 ...

  4. POJ 3660 Cow Contest. (传递闭包)【Floyd】

    <题目链接> 题目大意: 有n头牛, 给你m对关系(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少牛的排名. 解题分析: 首先,做这道题要明确,什么叫确定牛的排名.假设 ...

  5. atcoder Keyence Programming Contest 2020 题解

    比赛地址 A 题意:给一个\(n*m\)的初始为白色的矩阵,一次操作可以将一行或一列染成 黑色,问至少染出\(k\)个黑点的最少操作次数. \(n\),\(m\)<=100,\(k\)<= ...

  6. luogu P1452 [USACO03FALL]Beauty Contest G /【模板】旋转卡壳

    LINK:旋转卡壳 如题 是一道模板题. 容易想到n^2暴力 当然也能随机化选点 (还真有人过了 考虑旋转卡壳 其实就是对于某个点来说找到其最远的点. 在找的过程中需要借助一下个点的帮助 利用当前点到 ...

  7. 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 = ...

  8. 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)\).这就相当于 ...

  9. Atcoder Panasonic Programming Contest 2020

    前三题随便写,D题是一道dfs的水题,但当时没有找到规律,直接卡到结束 A - Kth Term /  Time Limit: 2 sec / Memory Limit: 1024 MB Score ...

随机推荐

  1. Databricks 第5篇:Databricks文件系统(DBFS)

    Databricks 文件系统 (DBFS,Databricks File System) 是一个装载到 Azure Databricks 工作区的分布式文件系统,可以在 Azure Databric ...

  2. 【SpringBoot1.x】SpringBoot1.x 消息

    SpringBoot1.x 消息 文章源码 概述 大多应用中,可通过消息服务中间件来提升系统异步通信.扩展解耦能力. 消息服务有两个重要概念,即消息代理(message broker)和目的地(des ...

  3. Centos 6 下安装 OSSEC-2.8.1 (一)

    ossec -2.8.1 安装: ## 1 ) 安装依赖包: RedHat / Centos / Fedora / Amazon Linux yum install -y pcre mysql mys ...

  4. mysql中更改字段属性实际上都做了哪些操作

     mysql> set profiling=1; Query OK, 0 rows affected (0.00 sec) mysql> alter table test modify n ...

  5. ctfhub技能树—sql注入—Cookie注入

    手注 打开靶机 查看页面信息 查找cookie 测试是否为cookie注入 抓包 尝试注入 成功查询到数据库名 查询表名 查询字段名 查询字段信息 成功拿到flag sqlmap 查询数据库名 pyt ...

  6. ctfhub技能树—RCE—过滤cat

    打开靶机 查看页面信息 构造payload 127.0.0.1 || ls 题目提示过滤了cat,但我还是想试试 果然不行 网页访问没有结果,应该和上题一样被注释了,使用和同样的方法进行解题 利用命令 ...

  7. +load和+initialize方法调用时机

    一.+load方法什么时候调用 +load方法会在runtime加载类.分类时调用(程序运行起来会先去加载调用+load 跟你引用没有引用其头文件没有关系).每个类.分类的+load,在程序运行过程中 ...

  8. java 利用异或^进行加密

    package com.zcj.eg001; import java.nio.charset.Charset; import org.junit.Test; public class Encrypti ...

  9. DockerFile关键字相关作用以及解释

    Dockerfile 关键字 作用 备注 FROM 指定父镜像 指定dockerfile基于那个image构建 MAINTAINER 作者信息 用来标明这个dockerfile谁写的 LABEL 标签 ...

  10. 从定义到AST及其遍历方式,一文带你搞懂Antlr4

    摘要:本文将首先介绍Antlr4 grammer的定义方式,如何通过Antlr4 grammer生成对应的AST,以及Antlr4 的两种AST遍历方式:Visitor方式和Listener方式. 1 ...