A - Minimal Square

题意

给两个完全一样的矩形(平行且不重叠) 求能覆盖两个矩形的最小正方形的面积

思路

只有两种摆放方式 将两个矩形上下并列或者左右并列 得到的新图形 长或者宽是之前的二倍

判断一下并排之后的图形长和宽的最小值即可

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 1010;int main() {int t;cin >> t;while (t--) {int a, b;cin >> a >> b;int minn = min(a, b);int maxn = max(a, b);int ans = max(minn * 2, maxn);cout << ans * ans << endl;}return 0;
}

B - Honest Coach

题意

将一组数据分成两组 使得其中一组的最大值和另一组的最小值相差最小

思路

sort后找到相邻两个数的差值的最小值即可

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 60;int a[N];
int main() {int t;cin >> t;while (t--) {int n;cin >> n;for (int i = 1;i <= n;++i)cin >> a[i];sort(a + 1, a + n + 1, [](int x, int y) {return x < y;});int res = INF;for (int i = 2;i <= n;++i)res = min(res, a[i] - a[i - 1]);cout << res << endl;}return 0;
}

C - Similar Pairs

题意

问:给出一个数组,求是否能够使所有的数都可以“类似”匹配。
”类似“:两个数具有相同的奇偶性,或差的绝对值为1。

思路

设奇数的个数为 x x x 偶数的个数为 y y y 因为 n n n为偶数 所以 x + y x + y x+y肯定为偶数

无非三种情况

① x x x 和 y y y都为偶数 显然满足条件

② x x x和 y y y 都为奇数 只要存在两个相邻的数 则他俩“类似” 且 x x x和 y y y都变成了偶数 也满足条件

③ x x x 和 y y y都为奇数 且没有相邻的数 显然无解

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 60;int a[N];int main() {int t;cin >> t;while (t--) {int n;cin >> n;int odd = 0,  even = 0;for (int i = 1;i <= n;++i) {cin >> a[i];if (a[i] & 1)odd++;else even++;}bool flag = false;if (odd % 2 == 0 && even % 2 == 0)puts("YES");else {sort(a + 1, a + n + 1, [](int x, int y) {return x < y;});for (int i = 2;i <= n;++i)if (a[i] - a[i - 1] == 1) {flag = true;}if (flag)puts("YES");else puts("NO");}}return 0;
}

D - Buying Shovels

题意

需要买 n n n件物品 有 k k k种包裹 第 k k k种包裹有 k k k件物品 用最小的包裹数买到需要的物品

思路

当 k > = n k >= n k>=n时毫无疑问答案为1

当 k < n k < n k<n 时 找到 n n n的小于等于 k k k的第一个因子

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 60;
set<int>s;
int a[N];
vector<int> divisors(int n) {vector<int >res;for (int i = 1;i <= n / i; ++i) {if (n % i == 0) {res.push_back(i);if (n / i != i)res.push_back(n / i);}}sort(res.begin(), res.end(), greater<int>());return res;
}
int main() {int t;cin >> t;while (t--) {int n, k;cin >> n >> k;if (k >= n) {cout << 1 << endl;continue;}else {int res = 0;vector<int>div = divisors(n);for (auto t : div) {if (t <= k) {res = n / t;break;}}cout << res << endl;}}return 0;
}

E - Polygon

题意

一个矩阵的左边和右边分别有一排大炮 大炮射出的子弹会在遇到边界或者1停止 并把当前位置变成1 给定一个矩阵 问能否通过大炮射出子弹 得到对应的矩阵

思路

参照样例不难发现 当一个位置是1时 当且仅当它的右方或下方为1

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 60;
char mp[N][N];
int main() {int t;cin >> t;while(t--){bool flag = true;int n;cin >> n;for (int i = 0;i < n;++i) for (int j = 0;j < n;++j) cin >> mp[i][j];for (int i = 0;i < n;++i) {for (int j = 0;j < n;++j) {if (mp[i][j] == '1') {if (i == n - 1)continue;else if (j == n - 1)continue;else if (mp[i + 1][j] != '1' && mp[i][j + 1] != '1') {flag = false;break;}}}}if (flag)puts("YES");else puts("NO");}return 0;
}

F - Spy-string

题意

给定 n n n个长度为 m m m的字符串 找出长度为m的任何字符串s,使得给定的n个字符串中的每一个在至多一个位置上与s不同。

思路

数据范围很小 暴力枚举即可

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 60;string s[20];
int n, m;
bool check(string& ans) {int cnt = 0;for (int i = 0;i < n;++i) {cnt = 0;for (int j = 0;j < m;++j) {if (s[i][j] != ans[j])++cnt;if (cnt > 1)return 0;}}return 1;
}
int main() {int t;cin >> t;while(t--){cin >> n >> m;bool flag = false;for (int i = 0;i < n;++i)cin >> s[i];string ans;for (int i = 0;i < m;++i) {for (char j = 'a';j <= 'z';++j) {ans = s[0];ans[i] = j;if (check(ans))flag = true;if (flag)break;}if (flag)break;}if (flag)cout << ans << endl;else puts("-1");}return 0;
}

G - A/B Matrix

题意

给你四个正整数 n 、 m 、 a 、 b n、m、a、b n、m、a、b 找出大小为 n × m n×m n×m且满足以下所有条件的任何此类矩形矩阵:

矩阵的每一行恰好包含 a a a个 1 1 1;
矩阵的每一列恰好包含 b b b个 1 1 1;
所有其他元素都是零。

可能不存在

思路

由题可知每一行的1乘以行数 等于 每一列的1乘以列数 当 n ∗ a ! = m ∗ b n*a \,\, != m*b n∗a!=m∗b时显然不符合题意

先考虑每行放 a a a个 1 1 1 那么如何保证每列都有 b b b个 1 1 1?其实只需要得到之前放了多少个 1 1 1,在这个基础上对该行放 1 1 1时,只需用之前的总个数对 m m m取模,就可以形成如下的一个对称的效果:

111100
110011
001111
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 60;int mp[N][N];int main() {int t;cin >> t;while(t--){int n, m, a, b;cin >> n >> m >> a >> b;if (n * a != m * b) {puts("NO");continue;}else {puts("YES");int s = 0;memset(mp, 0, sizeof mp);for (int i = 0;i < n;++i) {for (int j = s;j < s + a;++j) {mp[i][j % m] = 1;}s += a;}for (int i = 0;i < n;++i) {for (int j = 0;j < m;++j) {cout << mp[i][j];}cout << endl;}}}return 0;
}

H - Binary Median

题意

给一个长度为 m m m的二进制串 从中删去 n n n个不同的二进制串 问最终中位数为多少

思路

将二进制串转换成整数 分类讨论

将待删去的二进制串转换成十进制数 x x x 设 p p p为当前中位数

当 k k k为奇数时

​ ① x ≥ p x\geq p x≥p 中位数左移

​ ② x > p x > p x>p 不变

当 k k k为偶数时

​ ① x ≤ p x\leq p x≤p 中位数右移

​ ② x > p x > p x>p 不变

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 1010;int main() {int t;cin >> t;while (t--) {LL n, m;cin >> n >> m;set<LL>S;bool flag = true;LL k = 1LL << m;LL p = (k - 1) / 2;for (int i = 1;i <= n;++i) {string str;cin >> str;LL x = 0;for (int i = 0;i < str.size();++i) {if ((str[i] - '0') & 1)x += 1LL << (m - i - 1);}if (k & 1) {if (x >= p)while (S.count(--p));}else {if (x <= p)while (S.count(++p));}S.insert(x);--k;}string res = "";for (int i = 0;i < m;++i) {if (p & 1)res += "1";else res += "0";p >>= 1;}for (int i = res.size() - 1;i >= 0;--i)cout << res[i];cout << endl;}return 0;
}

Codeforces Round #644(Div. 3) A-H相关推荐

  1. Codeforces Round #644 (Div. 3) E.Polygon

    Codeforces Round #644 (Div. 3) E.Polygon 题目链接 Polygon is not only the best platform for developing p ...

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

    Codeforces Round #644 (Div. 3) D.Buying Shovels 题目链接 Polycarp wants to buy exactly n shovels. The sh ...

  3. Codeforces Round #644 (Div. 3) G.A/B Matrix

    Codeforces Round #644 (Div. 3) G.A/B Matrix 题目链接 You are given four positive integers n, m, a, b (1≤ ...

  4. Codeforces Round #644 (Div. 3) F.Spy-string

    Codeforces Round #644 (Div. 3) F.Spy-string 题目链接 You are given n strings a1,a2,-,an: all of them hav ...

  5. Codeforces Round #644 (Div. 3) H.Binary Median

    题目链接 Consider all binary strings of length m (1≤m≤60). A binary string is a string that consists of ...

  6. Codeforces Round #644 (Div. 3)(A-E)

    这场的A-E都是水题,就简单记录一下吧. Minimal Square CodeForces - 1360A 思路:我们令b=max(a,b),a=min(a,b). 如果b>=2*a的话,最终 ...

  7. Codeforces Round #694 (Div. 1 + Div2)(A ~ H,8题全,超高质量题解)【每日亿题】2021/2/1、2/2

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #694 (Div. 1 + Div2)(A ~ ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

最新文章

  1. Python使用scipy包将稀疏矩阵保存为Mtx格式和npz格式文件实战
  2. 【c语言】蓝桥杯算法提高 三角形面积
  3. pytorch中load和load_state_dict区别
  4. java 数组 反射_java数组的反射
  5. 干活干累了,刷一道题,一天保底两道,一年也就差不多刷完了 ----------7. Reverse Integer...
  6. php 获取数组最小值,php 获取数组中最小的值与键名的方法
  7. fortify扫描java_亲测有效的几种fortify扫描安全漏洞的解决方案
  8. VTK:vtkAreaPicker用法实战
  9. mysql 是否为空字符串_MySql判断是否为null或空字符串
  10. JTA 深度历险 - 原理与实现
  11. 软件开发人员想找的工作,随便聊聊,娱乐大家,请补充补充
  12. C++(11)--编程实践1-经典养成类游戏简单实践
  13. C# DataSet和DataTable详解
  14. SQLite Tutorial 1 在ubuntu上安装SQLite 3.8.2
  15. cmd窗口连接mongodb服务端
  16. 七种机器内部排序的原理与C语言实现,并计算它们的比较次数与移动次数。
  17. 在rhel6 64位环境下部署LNMP环境
  18. MySQL-快速入门(14)MySQL性能优化
  19. 趋势防毒墙网络版的安装部署(officescan)
  20. kindle资源网址

热门文章

  1. STM32F103RB 实作笔记(九)- PWM + SPI +MAX6675 整合试验 (正点原子 STM32F103 nano开发板)程式解析
  2. php 复制文件夹并压缩到最小_php获取所有文件并压缩
  3. 【力扣周赛#324】6266. 使用质因数之和替换后可以取到的最小值+6267. 添加边使所有节点度数都为偶数+6268. 查询树中环的长度
  4. 广义表C/C++实现详解
  5. Python基础操作_字典的遍历
  6. git gitgitgitgitgit
  7. 关于梯度消失,梯度爆炸的问题
  8. 【罗塞塔石碑】—My Lover(One.iso)
  9. 驱动程序开发:基于ICM20608六轴传感器 --- 使用Regmap API 的 SPI 读取数据 之 IIO驱动
  10. edge浏览器如何把网页放到桌面_win10系统怎么把Edge浏览器放到桌面?Edge怎么创建桌面快捷方式...