Codeforces Round #644 (Div. 3)
比赛链接: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)的更多相关文章
- [每日一题2020.06.11]Codeforces Round #644 (Div. 3) H
A-E见 : 这里 题目 我觉得很有必要把H拿出来单独发( 其实是今天懒得写题了 ) problem H 一个从 1 到 $ 2^m - 1$ 的长度为m的连续二进制序列, 删去指定的n个数, 问剩余 ...
- [每日一题2020.06.10]Codeforces Round #644 (Div. 3) ABCDEFG
花了5个多少小时总算把div3打通一次( 题目链接 problem A 题意 : 两个x*y的矩形不能重叠摆放, 要放进一个正方形正方形边长最小为多少 先求n = min(2x, 2y, x+y) 再 ...
- Codeforces Round #644 (Div. 3) D. Buying Shovels (数学)
题意:商店里有\(k\)个包裹,第\(i\)个包裹中含有\(i\)个物品,现在想要买\(n\)物品,你可以选择某一个包裹购买任意次,使得物品数刚好等于\(n\),求最少的购买次数. 题解:首先,假如\ ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
随机推荐
- Java入门-jdk安装与环境搭建
计算机 计算机的组成:硬件+软件 1.硬件 1.1CPU 好比人的大脑 主要负责数据的运算以及控制 1.2内存 存储数据(临时存储) 缺点: 如果断电,数据丢失 如果程序关闭或退出,数据丢失 1.3硬 ...
- java8 stream api流式编程
java8自带常用的函数式接口 Predicate boolean test(T t) 传入一个参数返回boolean值 Consumer void accept(T t) 传入一个参数,无返回值 F ...
- 不要把file,process或者super权限授予管理员以外的账号
file权限的主要作用是通过select ....into outfile 写到服务器上具有写权限的目录下,作为文本格式存放,具有权限的目录也就是启动mysql时的用户权限目录.(没有理解) 可以将有 ...
- kubernets之pod的标签
一 如何查看pod 的日志 1 通过执行命令查看日志信息 kubectl logs pod_name 二 创建带有标签的pod,一个范例的pod创建yaml文件如下所示 2.1 创建带有 ...
- AQS之ReentrantReadWriteLock精讲分析上篇
1.用法 1.1 定义一个安全的list集合 public class LockDemo { ArrayList<Integer> arrayList = new ArrayList< ...
- 1.2V转3V芯片,电路图很少就三个元件
1.2V的镍氢电池由于稳定高,应用产品也是很广,但是由于电压低,需要1.2V转3V芯片,来将1.2V的电压升压转3V,稳定输出供电. 一般性的1.2V转3V芯片,都是用PW5100比较多,固定输出电压 ...
- 给HTML页面设置自己的icon
原因: 不知道为什么,SpringBoot中自动设置icon失效了. 解决方法: 在head标签中添加自己想要使用的icon图片.后缀使用图片格式,不要使用.ico. <link href=&q ...
- HTTP Keep-Alive模式客户端与服务器如何判定传输完成
目录 长连接是什么 服务器如何知道已经完全接受客户端发送的数据 客户端如何知道已经完全接受服务端发送的数据 Transfer-Encoding transfer-coding与Content-Leng ...
- Flask源码流程分析(一)
Flask源码流程分析: 1.项目启动: 1.实例化Flask对象 1. 重要的加载项: * url_rule_class = Rule * url_map_class = Map * session ...
- file转化为binary对象发送给后台
具体代码如下: function filechange(e) { var file = $('#filed').get(0).files[0]; var fileSize = file.size, f ...