花了5个多少小时总算把div3打通一次(

题目链接

problem A

题意 : 两个x*y的矩形不能重叠摆放, 要放进一个正方形正方形边长最小为多少

先求n = min(2x, 2y, x+y)

再求max(n, x, y)即为正方形边长

  1. /*
  2. * Author: RoccoShi
  3. * Time: 2020-06-10 20:05:02
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. typedef long long ll;
  8. int main() {
  9. ios::sync_with_stdio(false);
  10. cin.tie(0);
  11. int t;
  12. cin >> t;
  13. while (t--) {
  14. int x, y;
  15. cin >> x >> y;
  16. int minn = min(x+x, y+y);
  17. minn = min(minn, x+y);
  18. int ans = max(minn, x);
  19. cout << pow(max(ans, y),2) << endl;
  20. }
  21. return 0;
  22. }

problem B

题意 : 找一个数组排序后相邻最小的两个数

排序后扫一遍

  1. /*
  2. * Author: RoccoShi
  3. * Time: 2020-06-10 20:05:02
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. typedef long long ll;
  8. int team[55];
  9. int main() {
  10. ios::sync_with_stdio(false);
  11. cin.tie(0);
  12. int t;
  13. cin >> t;
  14. while (t--) {
  15. int n;
  16. cin >> n;
  17. int minn = 9999;
  18. for (int i = 0; i < n; ++i)
  19. {
  20. cin >> team[i];
  21. }
  22. sort(team, team + n);
  23. for (int i = 1; i < n; ++i)
  24. {
  25. if (minn > team[i]-team[i-1]) {
  26. minn = team[i]-team[i-1];
  27. }
  28. }
  29. cout << minn <<endl;
  30. }
  31. return 0;
  32. }

problemC

题意 :

规则1 : 两个奇数或者两个偶数可以组一个team

规则2 : 相差为1的两个数可以组一个team

问 : 所有编号能否全部组成team

分别统计奇数和偶数的个数, 相差为1的两个数必为奇数和偶数

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

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

第二种必可以, 第一种只要有一对以上的规则2就可以变为第二种

  1. /*
  2. * Author: RoccoShi
  3. * Time: 2020-06-10 20:05:02
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. typedef long long ll;
  8. int a[55];
  9. int main() {
  10. ios::sync_with_stdio(false);
  11. cin.tie(0);
  12. int t;
  13. cin >> t;
  14. while (t--) {
  15. int n;
  16. cin >> n;
  17. int cntodd = 0, cnteven = 0, cntpair = 0;
  18. for (int i = 0; i < n; ++i) {
  19. cin >> a[i];
  20. if (a[i] % 2 == 1)
  21. cntodd++;
  22. else
  23. cnteven++;
  24. }
  25. sort(a, a+n);
  26. for (int i = 1; i < n; ++i)
  27. {
  28. if(a[i]-a[i-1]==1){
  29. cntpair++;
  30. i++;
  31. }
  32. }
  33. if(cnteven % 2 == 1 && cntodd % 2 ==1 ) {
  34. if(!cntpair)
  35. cout << "NO" <<endl;
  36. else
  37. cout << "YES" << endl;
  38. }
  39. else
  40. cout<< "YES" <<endl;
  41. }
  42. return 0;
  43. }

problem D

题意 :

找一个数n的所有因数里小于等于k的最大值

这题想了好久啊....

首先, 找一个数的因数 不用! 遍历! 所有! 数!

只需要把i从1遍历到\(\sqrt{n}\) 就可以了!

如果n可以整除i, 那么因数有两个, 一个是n/i, 还有一个是i

比如8, 我们遍历1,2就可以得到因数 1, 2, 4, 8

接下来只需要判断这个数是否<=k即可

如果k大于等于n, 直接输出1就可以了

  1. /*
  2. * Author: RoccoShi
  3. * Time: 2020-06-10 20:05:02
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. typedef long long ll;
  8. int main() {
  9. ios::sync_with_stdio(false);
  10. cin.tie(0);
  11. int t;
  12. cin >> t;
  13. while (t--) {
  14. int n, k;
  15. cin >> n >> k;
  16. if ( k >= n) {
  17. cout << 1 << endl;
  18. }
  19. else
  20. {
  21. int m = sqrt(n);
  22. int ans = n;
  23. for (int i = m; i >= 1; --i) // 叉子的个数
  24. {
  25. if(n % i == 0){
  26. if(i <= k) ans = min(ans, n/i);
  27. if(n/i <= k) ans = min(ans, i); // 想了好久啊烦
  28. }
  29. }
  30. cout << ans << endl;
  31. }
  32. }
  33. return 0;
  34. }

problem E

题意 : 俄罗斯方块类, n*n的正方形上面和左边各有n个发射口, 发射顺序自定义, 1为该处有个块, 0为没有. 问是否能堆叠成给定的形状

扫描一波判断所有的1下面或者右边是否有个0, 如果都莫得直接输出NO

  1. /*
  2. * Author: RoccoShi
  3. * Time: 2020-06-10 20:05:02
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. typedef long long ll;
  8. int x[55][55];
  9. int main() {
  10. ios::sync_with_stdio(false);
  11. cin.tie(0);
  12. int t;
  13. cin >> t;
  14. while (t--) {
  15. int n;
  16. cin >> n;
  17. bool flag = 1;
  18. char s;
  19. cin.get();
  20. for (int i = 0; i < n; ++i)
  21. {
  22. for (int j = 0; j < n; ++j)
  23. {
  24. s = cin.get();
  25. //cout.put(s);
  26. x[i][j] = s=='0'?0:1;
  27. }
  28. s=cin.get();
  29. //cout.put(s);
  30. }
  31. for (int i = 0; i < n; ++i)
  32. {
  33. for (int j = 0; j < n; ++j)
  34. {
  35. if(i == n-1 || j == n-1)
  36. continue;
  37. else if(x[i][j] == 1)
  38. {
  39. if((x[i][j+1] || x[i+1][j]) == 0)
  40. flag = 0;
  41. }
  42. }
  43. }
  44. if(flag)
  45. cout << "YES" << endl;
  46. else
  47. cout << "NO" << endl;
  48. }
  49. return 0;
  50. }

problem F

题意 : 给n个字符串问是否存在一个字符串与每个字符串都只有一个地方不同

给定范围很小, 考虑直接暴力, 最大遍历不过为\(10 \times 10 \times 26\)

直接把字符串存起, 然后遍历判断

  1. /*
  2. * Author: RoccoShi
  3. * Time: 2020-06-10 20:05:02
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. typedef long long ll;
  8. vector<string> s(15);
  9. string x(15, '\0');
  10. int m, n;
  11. bool is1(){
  12. for (int i = 0; i < n; ++i)
  13. {
  14. int cnt = 0;
  15. for (int j = 0; j < m; ++j)
  16. {
  17. cnt += (x[j] == s[i][j] ? 0 : 1 );
  18. }
  19. if(cnt > 1)
  20. return false;
  21. }
  22. return true;
  23. }
  24. int main() {
  25. ios::sync_with_stdio(false);
  26. cin.tie(0);
  27. int t;
  28. cin >> t;
  29. while(t--) {
  30. bool flag = false;
  31. cin >> n >> m;
  32. for (int i = 0; i < n; ++i)
  33. cin >> s[i];
  34. for (int i = 0; i < m; ++i)
  35. {
  36. x[i] = s[0][i];
  37. }
  38. for (int i = 0; i < m; ++i)
  39. {
  40. for (int j = 'a'; j <= 'z'; ++j) {
  41. x[i] = j;
  42. if(is1()){
  43. flag = true;
  44. break;
  45. }
  46. }
  47. if(flag)
  48. break;
  49. x[i] = s[0][i];
  50. }
  51. if(flag == 1) {
  52. for (int i = 0; i < m; ++i)
  53. {
  54. cout<< x[i];
  55. }
  56. cout << endl;
  57. }
  58. else
  59. cout << "-1" << endl;
  60. }
  61. return 0;
  62. }

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

  1. /*
  2. * Author: RoccoShi
  3. * Time: 2020-06-10 20:05:02
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. typedef long long ll;
  8. const int maxn = 55;
  9. int mp[maxn][maxn];
  10. int main() {
  11. ios::sync_with_stdio(false);
  12. cin.tie(0);
  13. int t;
  14. cin >> t;
  15. int n, a, m, b;
  16. while(t--) {
  17. cin >> n >> m >> a >> b;
  18. if(n*a != m*b)
  19. {
  20. cout << "NO" << endl;
  21. }
  22. else
  23. {
  24. cout << "YES" << endl;
  25. int pos = 0;
  26. for (int i = 0; i < n; ++i)
  27. {
  28. for (int j = 0; j < a; ++j)
  29. {
  30. mp[i][pos++] = 1;
  31. pos %= m;
  32. }
  33. }
  34. for (int i = 0; i < n; ++i)
  35. {
  36. for (int j = 0; j < m; ++j) {
  37. cout << mp[i][j];
  38. mp[i][j] = 0;
  39. }
  40. cout << endl;
  41. }
  42. }
  43. }
  44. return 0;
  45. }

[每日一题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. JDK安装与配置环境变量

    1.JDK的安装 (1).为什么安装jdk? JDK是java软件开发包的简称,要想开发java程序就必须安装JDK.没有JDK的话,无法编译Java程序. (2).开始安装jdk 1.官网下载jdk ...

  2. Java数组声明创建和使用以及多维数组、Arrays类、稀疏数组

    目录 数组概述 数组声明创建 内存分析 java内存分析 堆 栈 方法区 三种初始化 静态初始化 动态初始化 数组的默认初始化 数组的四个基本特点 数组边界 小结: 数组使用 数组基础使用 For E ...

  3. MyBatis中的命名空间namespace的作用

    1.定义mapper接口,面向接口编程. 2.在大型项目中,可能存在大量的SQL语句,这时候为每个SQL语句起一个唯一的标识(ID)就变得并不容易了.为了解决这个问题,在MyBatis中,可以为每个映 ...

  4. Docker scratch 无法正常运行golang二进制程序的问题

    使用Docker构建容器能够极大的降低运维成本,提高部署效率,同时非常方便对服务的平行扩展.然而在构建容器镜像过程中的,存在着一个难以避免的问题,就是如果使用常见的发行版本作为程序运行的基础环境,那么 ...

  5. echarts实现漏斗转化率图表效果

    1.在用echarts实现图表的旅途中遇到这样一个需求,用柱图展示漏斗转化效果,下图展示: 别的不多说了,就说解决方式吧,用的series中的markpoint来实现. option.series[0 ...

  6. CTR学习笔记&代码实现6-深度ctr模型 后浪 xDeepFM/FiBiNET

    xDeepFM用改良的DCN替代了DeepFM的FM部分来学习组合特征信息,而FiBiNET则是应用SENET加入了特征权重比NFM,AFM更进了一步.在看两个model前建议对DeepFM, Dee ...

  7. Chisel3 - util - Valid

    https://mp.weixin.qq.com/s/L5eAwv--WzZdr-CfW2-XNA   Chisel提供的Valid接口.如果valid为置1,则表明输出的bits有效:反之,则输出无 ...

  8. java eclipse tomcat

    Port 8080 required by Tomcat v9.0 Server at localhost is already in use. The server may already be r ...

  9. CPU efficiency测量标准:DMIPS

    DMIPS:Dhrystone Million Instructions executed Per Second ,主要用于测整数计算能力.   1.Dhrystone:是测量处理器运算能力的最常见基 ...

  10. Java实现 LeetCode 665 非递减数列(暴力)

    665. 非递减数列 给你一个长度为 n 的整数数组,请你判断在 最多 改变 1 个元素的情况下,该数组能否变成一个非递减数列. 我们是这样定义一个非递减数列的: 对于数组中所有的 i (1 < ...