[每日一题2020.06.10]Codeforces Round #644 (Div. 3) ABCDEFG
花了5个多少小时总算把div3打通一次(
problem A
题意 : 两个x*y的矩形不能重叠摆放, 要放进一个正方形正方形边长最小为多少
先求n = min(2x, 2y, x+y)
再求max(n, x, y)即为正方形边长
/*
* Author: RoccoShi
* Time: 2020-06-10 20:05:02
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int x, y;
cin >> x >> y;
int minn = min(x+x, y+y);
minn = min(minn, x+y);
int ans = max(minn, x);
cout << pow(max(ans, y),2) << endl;
}
return 0;
}
problem B
题意 : 找一个数组排序后相邻最小的两个数
排序后扫一遍
/*
* Author: RoccoShi
* Time: 2020-06-10 20:05:02
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int team[55];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int minn = 9999;
for (int i = 0; i < n; ++i)
{
cin >> team[i];
}
sort(team, team + n);
for (int i = 1; i < n; ++i)
{
if (minn > team[i]-team[i-1]) {
minn = team[i]-team[i-1];
}
}
cout << minn <<endl;
}
return 0;
}
problemC
题意 :
规则1 : 两个奇数或者两个偶数可以组一个team
规则2 : 相差为1的两个数可以组一个team
问 : 所有编号能否全部组成team
分别统计奇数和偶数的个数, 相差为1的两个数必为奇数和偶数
奇数和偶数的个数有两种情况 :
- 均为奇数
- 均为偶数
第二种必可以, 第一种只要有一对以上的规则2就可以变为第二种
/*
* Author: RoccoShi
* Time: 2020-06-10 20:05:02
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[55];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int cntodd = 0, cnteven = 0, cntpair = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] % 2 == 1)
cntodd++;
else
cnteven++;
}
sort(a, a+n);
for (int i = 1; i < n; ++i)
{
if(a[i]-a[i-1]==1){
cntpair++;
i++;
}
}
if(cnteven % 2 == 1 && cntodd % 2 ==1 ) {
if(!cntpair)
cout << "NO" <<endl;
else
cout << "YES" << endl;
}
else
cout<< "YES" <<endl;
}
return 0;
}
problem D
题意 :
找一个数n的所有因数里小于等于k的最大值
这题想了好久啊....
首先, 找一个数的因数 不用! 遍历! 所有! 数!
只需要把i从1遍历到\(\sqrt{n}\) 就可以了!
如果n可以整除i, 那么因数有两个, 一个是n/i, 还有一个是i
比如8, 我们遍历1,2就可以得到因数 1, 2, 4, 8
接下来只需要判断这个数是否<=k即可
如果k大于等于n, 直接输出1就可以了
/*
* Author: RoccoShi
* Time: 2020-06-10 20:05:02
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
if ( k >= n) {
cout << 1 << endl;
}
else
{
int m = sqrt(n);
int ans = n;
for (int i = m; i >= 1; --i) // 叉子的个数
{
if(n % i == 0){
if(i <= k) ans = min(ans, n/i);
if(n/i <= k) ans = min(ans, i); // 想了好久啊烦
}
}
cout << ans << endl;
}
}
return 0;
}
problem E
题意 : 俄罗斯方块类, n*n的正方形上面和左边各有n个发射口, 发射顺序自定义, 1为该处有个块, 0为没有. 问是否能堆叠成给定的形状
扫描一波判断所有的1下面或者右边是否有个0, 如果都莫得直接输出NO
/*
* Author: RoccoShi
* Time: 2020-06-10 20:05:02
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int x[55][55];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
bool flag = 1;
char s;
cin.get();
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
s = cin.get();
//cout.put(s);
x[i][j] = s=='0'?0:1;
}
s=cin.get();
//cout.put(s);
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if(i == n-1 || j == n-1)
continue;
else if(x[i][j] == 1)
{
if((x[i][j+1] || x[i+1][j]) == 0)
flag = 0;
}
}
}
if(flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
problem F
题意 : 给n个字符串问是否存在一个字符串与每个字符串都只有一个地方不同
给定范围很小, 考虑直接暴力, 最大遍历不过为\(10 \times 10 \times 26\)
直接把字符串存起, 然后遍历判断
/*
* Author: RoccoShi
* Time: 2020-06-10 20:05:02
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<string> s(15);
string x(15, '\0');
int m, n;
bool is1(){
for (int i = 0; i < n; ++i)
{
int cnt = 0;
for (int j = 0; j < m; ++j)
{
cnt += (x[j] == s[i][j] ? 0 : 1 );
}
if(cnt > 1)
return false;
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--) {
bool flag = false;
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> s[i];
for (int i = 0; i < m; ++i)
{
x[i] = s[0][i];
}
for (int i = 0; i < m; ++i)
{
for (int j = 'a'; j <= 'z'; ++j) {
x[i] = j;
if(is1()){
flag = true;
break;
}
}
if(flag)
break;
x[i] = s[0][i];
}
if(flag == 1) {
for (int i = 0; i < m; ++i)
{
cout<< x[i];
}
cout << endl;
}
else
cout << "-1" << endl;
}
return 0;
}
problem G
题意 : 给定n*m的矩阵和数字a, b. 问是否存在每行有a个1且每列有b个1的排列
首先判断是否\(n \times a = b \times m\) , 如果是那么必存在这样的排列
怎么排? 循环排列即可
比如n = 4, m = 6, a = 3, b = 2
就
111000
000111
111000
000111
/*
* Author: RoccoShi
* Time: 2020-06-10 20:05:02
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 55;
int mp[maxn][maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
int n, a, m, b;
while(t--) {
cin >> n >> m >> a >> b;
if(n*a != m*b)
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
int pos = 0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < a; ++j)
{
mp[i][pos++] = 1;
pos %= m;
}
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j) {
cout << mp[i][j];
mp[i][j] = 0;
}
cout << endl;
}
}
}
return 0;
}
[每日一题2020.06.10]Codeforces Round #644 (Div. 3) ABCDEFG的更多相关文章
- [每日一题2020.06.11]Codeforces Round #644 (Div. 3) H
A-E见 : 这里 题目 我觉得很有必要把H拿出来单独发( 其实是今天懒得写题了 ) problem H 一个从 1 到 $ 2^m - 1$ 的长度为m的连续二进制序列, 删去指定的n个数, 问剩余 ...
- [每日一题2020.06.07]codeforces Round #627 (Div. 3)
problem A /* * Author: RoccoShi * Time: 2020-06-07 19:37:51 */ #include <bits/stdc++.h> using ...
- [每日一题2020.06.13]leetcode #739 #15 单调栈 双指针查找
739 每日温度 ( 单调栈 ) 题目 : https://leetcode-cn.com/problems/daily-temperatures/ 题意 : 找到数组每一个元素之后第一个大于它的元素 ...
- [每日一题2020.06.08]洛谷P1605 DFS
今天cf又杯具的只写出2题, 虽然AB题20分钟左右就搞定了, 但是CD写了2个小时也没写出来 D题我用到了DFS, 虽然必不正确, 但是我至少发现了一个问题, 那就是我连DFS都忘了, 于是怒找DF ...
- [每日一题2020.06.17] leetcode周赛T3 5438 制作m束花所需的最少天数 二分搜索
题目链接 这题我开始一直在想如何在数组上dp操作搜索区间, 很蠢, 实际上用二分查找的方法可以很快的解决 首先我们通过一个函数判断第x天是否符合题意, 如果x天可以做出m束花, 那么大于m的天数必然可 ...
- [每日一题2020.06.14]leetcode #70 爬楼梯 斐波那契数列 记忆化搜索 递推通项公式
题目链接 题意 : 求斐波那契数列第n项 很简单一道题, 写它是因为想水一篇博客 勾起了我的回忆 首先, 求斐波那契数列, 一定 不 要 用 递归 ! 依稀记得当年校赛, 我在第一题交了20发超时, ...
- [每日一题2020.06.16] leetcode双周赛T3 5423 找两个和为目标值且不重叠的子数组 DP, 前缀和
题目链接 给你一个整数数组 arr 和一个整数值 target . 请你在 arr 中找 两个互不重叠的子数组 且它们的和都等于 target .可能会有多种方案,请你返回满足要求的两个子数组长度和的 ...
- [每日一题2020.06.15]P1226 【模板】快速幂取余运算
我是题目 快速幂就是快速求 \(a^b\)的一种算法 快速幂 思想 : 比如我要求 \(6^9\) 首先将幂转化为二进制形式 : \[6^9 = 6^{1001} \tag{1} \] 可以得到 : ...
- [每日一题2020.06.12]P3375 【模板】KMP字符串匹配
题目链接 关于kmp : https://www.cnblogs.com/roccoshi/p/13096988.html 关于kmp, 想了很久, 我觉得不应该放在这里写, 另开一贴记录一下. #i ...
随机推荐
- POJ1733
题目链接:https://vjudge.net/problem/POJ-1733 解题思路:并查集+离散化 AC代码: #include <iostream> #include <c ...
- hibernate 异常分析:java.lang.NoClassDefFoundError: org/hibernate/Session
原因: NoClassDefFoundError的含义就是说编译器找不到org/hibernate/Session这个类的定义 解决方法: 1.检查java中是否导入hibernate 包 impor ...
- Linux 番茄时钟 定时 取消 快捷方式
shell 脚本 clock.sh #!/bin/bash if [ $1 == 0 ] then at -d `atq | awk -v ORS=" " '{a[NR]=$1} ...
- Android_存储之scoped storage&媒体文件
Scoped storage 文件存储介绍了内部存储和外部存储相关的内容.因为外部存储容易读写,所以在手机中经常看到很多“乱七八糟”的文件或文件夹,这些就是应用肆意创建的. Android Q(10) ...
- 线程池 & 线程调度
线程池1. 第四种获取线程的方法:线程池,一个 ExecutorService,它使用可能的几个池线程之 一执行每个提交的任务, 通常使用 Executors 工厂方法配置. 2. 线程池可以解决两个 ...
- Python编程基本规范
1.命名规范 类:类的名称一般为名词,且以驼峰形式(即每个单词首字母要大写,其余字母小写,单词之间无间隔符号)给出. 函数:一般以动词开头,函数名称要准确.简要地概括本函数的作用.函数名一律小写,如有 ...
- 中国电信中兴F412光猫——IPTV与网络单线复用
标题: 中国电信中兴F412光猫--IPTV与网络单线复用 作者: 梦幻之心星 347369787@QQ.com 标签: [光猫, IPTV] 目录: 路由器 日期: 2019-2-30 目录 第一步 ...
- Rocket - debug - SBA
https://mp.weixin.qq.com/s/eFOHrEhvq2PlEJ14j2vlhg 简单介绍SBA的实现. 1. SystemBusAccessState 系统总线访问状态: 分别是: ...
- 【zookeeper】安装教程文档需下载
请查看文件https://download.csdn.net/download/qq_42158942/11846847 zookeeper的作用 • ZooKeeper 是一个开源的分布式协调服务, ...
- Java 蓝桥杯 算法训练(VIP) 最大体积
最大体积 问题描述 每个物品有一定的体积(废话),不同的物品组合,装入背包会战用一定的总体积. 假如每个物品有无限件可用,那么有些体积是永远也装不出来的. 为了尽量装满背包,附中的OIER想要研究一下 ...