花了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的两个数必为奇数和偶数

奇数和偶数的个数有两种情况 :

  1. 均为奇数
  2. 均为偶数

第二种必可以, 第一种只要有一对以上的规则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的更多相关文章

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

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

  2. [每日一题2020.06.07]codeforces Round #627 (Div. 3)

    problem A /* * Author: RoccoShi * Time: 2020-06-07 19:37:51 */ #include <bits/stdc++.h> using ...

  3. [每日一题2020.06.13]leetcode #739 #15 单调栈 双指针查找

    739 每日温度 ( 单调栈 ) 题目 : https://leetcode-cn.com/problems/daily-temperatures/ 题意 : 找到数组每一个元素之后第一个大于它的元素 ...

  4. [每日一题2020.06.08]洛谷P1605 DFS

    今天cf又杯具的只写出2题, 虽然AB题20分钟左右就搞定了, 但是CD写了2个小时也没写出来 D题我用到了DFS, 虽然必不正确, 但是我至少发现了一个问题, 那就是我连DFS都忘了, 于是怒找DF ...

  5. [每日一题2020.06.17] leetcode周赛T3 5438 制作m束花所需的最少天数 二分搜索

    题目链接 这题我开始一直在想如何在数组上dp操作搜索区间, 很蠢, 实际上用二分查找的方法可以很快的解决 首先我们通过一个函数判断第x天是否符合题意, 如果x天可以做出m束花, 那么大于m的天数必然可 ...

  6. [每日一题2020.06.14]leetcode #70 爬楼梯 斐波那契数列 记忆化搜索 递推通项公式

    题目链接 题意 : 求斐波那契数列第n项 很简单一道题, 写它是因为想水一篇博客 勾起了我的回忆 首先, 求斐波那契数列, 一定 不 要 用 递归 ! 依稀记得当年校赛, 我在第一题交了20发超时, ...

  7. [每日一题2020.06.16] leetcode双周赛T3 5423 找两个和为目标值且不重叠的子数组 DP, 前缀和

    题目链接 给你一个整数数组 arr 和一个整数值 target . 请你在 arr 中找 两个互不重叠的子数组 且它们的和都等于 target .可能会有多种方案,请你返回满足要求的两个子数组长度和的 ...

  8. [每日一题2020.06.15]P1226 【模板】快速幂取余运算

    我是题目 快速幂就是快速求 \(a^b\)的一种算法 快速幂 思想 : 比如我要求 \(6^9\) 首先将幂转化为二进制形式 : \[6^9 = 6^{1001} \tag{1} \] 可以得到 : ...

  9. [每日一题2020.06.12]P3375 【模板】KMP字符串匹配

    题目链接 关于kmp : https://www.cnblogs.com/roccoshi/p/13096988.html 关于kmp, 想了很久, 我觉得不应该放在这里写, 另开一贴记录一下. #i ...

随机推荐

  1. VueRouter小手册

    目录 一. 了解router 二. 工作流程 三. 简单的Demo 四. 理解template和route的组合 五. Vue-Router-GoBack记录返回 六. Router-Link 七. ...

  2. Shift - And字符串快速处理 hdu5972+cf

    基础知识介绍 KMP就是不断往前找1的位置,而ShiftAnd经过三步处理已经完成这个迭代的过程了 如果匹配两个字符集有限的字符串的话,那么Shift-And比kmp要快,找区间内某字符串出现的数目也 ...

  3. C语言基础知识(五)——数组与指针的等价表示

    void f(void) { int * p; int a[3] = {1,2,3}; p = a; printf("%d %d", a[0], p[0], *(a+1), *(p ...

  4. 仿开源框架从零到一完整实现高性能、可扩展的RPC框架 | 6个月做成教程免费送

    去年年就在写一本付费小册,今年年初基本上就写完了,本来预计计划是春节上线结果由于平台的原因一直拖着没上.五一前跟平台联系给的反馈是五月份能上,结果平台又在重构,停止小册的申请和上线,最后我考虑了一下决 ...

  5. html浏览器高度和宽度和其他dom获取

    1.获取网页可见区域的宽度:document.body.clientWidth ; 2.获取网页可见区域的高度:document.body.clientHeight; 3.获取 网页可见区域宽:doc ...

  6. 不懂代码?没关系,照样可以做SaaS软件开发

    众所周知,一家标准化的企业的日常运营管理都需要一个强大的中枢或中台管理系统来统筹整个企业或是整个集团的运作,这个强大的中台管理系统就相当于是企业的引擎.在引擎的带动下,汽车可以快速的飞驰起来,同样,在 ...

  7. 了解Lombok插件

    Lombok是什么 Lombok可以通过注解形式帮助开发人员解决POJO冗长问题,帮助构造简洁和规范的代码,通过注解可产生相应的方法. Lombok如何在IDEA中使用 我们都知道,使用一种工具,一定 ...

  8. Maven快速入门(一)Maven介绍及环境搭建

    做开发的程序员都知道,在系统开发需要各自各样的框架.工具.其中有一种工具不管你是初级程序员还是高级程序员都必须熟练掌握的,那就是项目管理工具(maven.ant.gradle).接下来就总结Maven ...

  9. [Objective-C] 011_数据持久化_NSKeyedArchiver

    在日常开发中对于NSString.NSDictionary.NSArray.NSData.NSNumber这些基本类的数据持久化,可以用属性列表的方法持久化到.plist 文件中.但是一些我们自定义的 ...

  10. Wilson's theorem在RSA题中运用

    引言 最近一段时间在再练习数论相关的密码学题目,自己之前对于数论掌握不是很熟练,借此机会先对数论基本的四大定理进行练习 这次的练习时基于Wilson's theorem(威尔逊定理)在RSA题目中的练 ...