比赛链接:https://codeforces.com/contest/1360

A - Minimal Square

题意

计算能包含两个 $a \times b$ 矩形的最小正方形的面积。

题解

将两个矩形的较短边拼在一起即可。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int a, b; cin >> a >> b;
if (a > b) swap(a, b);
int mx = max(a + a, b);
cout << mx * mx << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

B - Honest Coach

题意

将 $n$ 个数分为两组,使得一组的最大值与另一组的最小值相差最小。

题解

将 $n$ 个数排序后从相差最小的两个数间分开即可。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
int a[n] = {};
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int mi = INT_MAX;
for (int i = 1; i < n; i++)
mi = min(mi, a[i] - a[i - 1]);
cout << mi << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

C - Similar Pairs

题意

将偶数个数两两配对,要求配对的数具有相同的奇偶性或相差为 $1$ 。

题解

如果奇偶数均有偶数个则它们内部两两配对即可,否则找出一对相差为 $1$ 奇偶数配对,余下的奇偶数个数又均为偶数。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
vector<int> odd;
map<int, int> even;
for (int i = 0; i < n; i++) {
int x; cin >> x;
if (x % 2) odd.push_back(x);
else even[x]++;
}
bool flag = false;
if (odd.size() % 2) {
for (auto x : odd)
if (even[x - 1] or even[x + 1])
flag = true;
} else flag = true;
cout << (flag ? "YES" : "NO") << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

D - Buying Shovels

题意

要买刚好 $n$ 个铲子,有 $k$ 种包装的铲子,每种包装内的铲子数量分别为 $1{\sim}k$,只能挑一种包装购买,计算同一包装最少需要买多少个。

题解

在 $n$ 的因子中找小于等于 $k$ 的最大因子,$n$ 除以该最大因子即为最少个数。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n, k; cin >> n >> k;
int ans = n;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (i <= k) ans = min(ans, n / i);
if (n / i <= k) ans = min(ans, i);
}
}
cout << ans << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

E - Polygon

题意

$n \times n$ 网格的最上边一排和最左边一列外各有 $n$ 门大炮,大炮可向网格内发射 $1$,每次发射的 $1$ 遇到边界或 $1$ 停下来,判断是否存在某种发射顺序可以得到给出的网格。

题解

因为大炮的位置在左和上,所以每个非右下边界的 $1$ 右或下方一定有一个 $1$ 。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
char MP[n][n] = {};
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> MP[i][j];
bool flag = true;
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < n - 1; j++)
if (MP[i][j] == '1' and MP[i + 1][j] != '1' and MP[i][j + 1] != '1')
flag = false;
cout << (flag ? "YES" : "NO") << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

F - Spy-string

题意

给出 $n$ 个字符串,找出一个字符串,要求该字符串与每个字符串相差最多一个字母。

题解

记录每个字符串的衍生字符串,被衍生了 $n$ 次的字符串即为答案。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n, m; cin >> n >> m;
map<string, int> mp;
for (int i = 0; i < n; i++) {
string s; cin >> s;
set<string> st;
for (int j = 0; j < m; j++) {
char t = s[j];
for (int k = 0; k < 26; k++) {
if (t - k >= 'a') {
s[j] = t - k;
st.insert(s);
}
if (t + k <= 'z') {
s[j] = t + k;
st.insert(s);
}
}
s[j] = t;
}
for (auto i : st) ++mp[i];
}
for (auto i : mp) {
if (i.second == n) {
cout << i.first << "\n";
return;
}
}
cout << -1 << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

G - A/B Matrix

题意

构造一个 $n \times m$ 的 $01$ 矩阵,使得每行有 $a$ 个 $1$,每列有 $b$ 个 $1$ 。

题解

所有行的 $1$ 的个数:$n \times a$

所有列的 $1$ 的个数:$m \times b$

如果存在满足要求的 $01$ 矩阵,二者必须相等,之后按行或列贪心构造即可。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n, m, a, b; cin >> n >> m >> a >> b;
if (n * a != m * b) {
cout << "NO" << "\n";
return;
}
bool MP[n][m] = {};
int col = 0;
for (int row = 0; row < n; row++) {
for (int i = 0; i < a; i++) {
MP[row][col] = '1';
if (++col == m) col = 0;
}
}
cout << "YES" << "\n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
cout << MP[i][j];
cout << "\n";
}
} int main() {
int t; cin >> t;
while (t--) solve();
}

H - Binary Median

题意

$0 \sim 2^m - 1$ 中去掉 $n$ 个数后第 $\lfloor \frac{k - 1}{2} \rfloor$ 个数是多少(即余下的 $k$ 个数的中位数)。

题解

对于中位数来说,如果去掉的数的值小于等于它自身,那么中位数的值会向右偏移一,最小的中位数即为刚开始去掉 $n$ 个最大的数,从小到大统计是否有值小于等于中位数,同时更新中位数的值即可。

代码

#include <bits/stdc++.h>
using ll = long long;
using namespace std; void solve() {
int n, m; cin >> n >> m;
ll ans = ((1LL << m) - n - 1) / 2;
ll a[n] = {};
for (int i = 0; i < n; i++) {
string s; cin >> s;
a[i] = bitset<64>(s).to_ullong();
}
sort(a, a + n);
for (auto i : a) ans += (i <= ans);
cout << bitset<64>(ans).to_string().substr(64 - m) << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

Codeforces Round #644 (Div. 3)的更多相关文章

  1. [每日一题2020.06.11]Codeforces Round #644 (Div. 3) H

    A-E见 : 这里 题目 我觉得很有必要把H拿出来单独发( 其实是今天懒得写题了 ) problem H 一个从 1 到 $ 2^m - 1$ 的长度为m的连续二进制序列, 删去指定的n个数, 问剩余 ...

  2. [每日一题2020.06.10]Codeforces Round #644 (Div. 3) ABCDEFG

    花了5个多少小时总算把div3打通一次( 题目链接 problem A 题意 : 两个x*y的矩形不能重叠摆放, 要放进一个正方形正方形边长最小为多少 先求n = min(2x, 2y, x+y) 再 ...

  3. Codeforces Round #644 (Div. 3) D. Buying Shovels (数学)

    题意:商店里有\(k\)个包裹,第\(i\)个包裹中含有\(i\)个物品,现在想要买\(n\)物品,你可以选择某一个包裹购买任意次,使得物品数刚好等于\(n\),求最少的购买次数. 题解:首先,假如\ ...

  4. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  9. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

随机推荐

  1. JavaScript 内存详解 & 分析指南

    前言 JavaScript 诞生于 1995 年,最初被设计用于网页内的表单验证. 这些年来 JavaScript 成长飞速,生态圈日益壮大,成为了最受程序员欢迎的开发语言之一.并且现在的 JavaS ...

  2. ubuntu 上搭建 go的开发环境 vscode

    原文链接: https://astaxie.gitbooks.io/build-web-application-with-golang/zh/01.4.html 原本我是在windows下进行go的环 ...

  3. Hbase 手动执行MajorCompation

    说明: Major Compaction 的作用: 1.将一个Region下的所有StoreFile合并成一个StoreFile文件 2.对于删除.过期.多余版本的数据进行清除 由于MajorComp ...

  4. docker 报错: Cannot connect to the Docker daemon at unix:///var/run/docker.sock.

    最近在 Windows 子系统 WSL 上面安装了一个 ubuntu18.04, 安装完docker 跑 hello-world 的时候报错了 docker: Cannot connect to th ...

  5. library cache pin解决方法

    library cache pin大部分都是因为编译存储过程造成的 查找造成问题的数据库对象(一般为存储过程) SELECT * FROM v$session_wait WHERE event = ' ...

  6. sentinel-实战

    sentinel-实战笔记 什么是Sentinel Sentinel是阿里开源的项目,提供了流量控制.熔断降级.系统负载保护等多个维度来保障服务之间的稳定性. Sentinel主要特性: 获取Sent ...

  7. Linux中让终端输入变为非阻塞的三种方法

    介绍 在linux下每打开一个终端,系统自动的就打开了三个文件,它们的文件描述符分别为0,1,2,功能分别是"标准输入"."标准输出"和"标准错误输出 ...

  8. nfs samba文件共享服务

    (注意:实验之前强关闭selinux和防火墙) 一丶nfs ① 1.服务端 启动服务 systemctl start nfs.service   配置文件 vim /etc/exports share ...

  9. Vue基础之Vue组件

    Vue基础之Vue组件 // 组件是可以复用的Vue实例! // 可以把经常重复的功能封装为组件!

  10. code-server scala error: object apache is not a member of package org

    原因是scala缺少包,需要把spark或对应的包放入scala目录下的lib,然后重启主机,在terminal输入reboot即可. 如果不重启主机,则在交互式编程中可以成功import.但是直接在 ...