目录

杂谈

A. Madoka and Math Dad

B. Madoka and the Elegant Gift

C. Madoka and Childish Pranks


杂谈

又是一场离谱掉分场(;´д`)ゞ,AB题就跟脑子宕机了一样。

A题一开始分类就分错了,按奇偶分,过了样例,自信满满地交了一发,TLE,又试了个例子,发现不对,死循环了......后来反应过来,AC时已经18分钟了......

B题觉得思路无懈可击,然后交了一发,WA3,然后以为是没有特判,又交了一发,还是WA3,最后发现判断函数里应该是 i < n 之类的,写成了 i <= n......

C题是这三题中最顺利的了,出了思路之后很快想到了代码实现,然后一波过了。

最近罚时有点严重,细节处理出现了挺多问题的,要多注意一些细节了(ノへ ̄、)。

A. Madoka and Math Dad

题目链接:Problem - A - Codeforces

题目大意:给定一个数 n 表示一个数的各个数位之和,要求该数不出现 0,且相邻两位数字不能相同,求这个数的最大值。

解题思路:要想让数最大,只能使用 1,2 两个数字,这样组成的数数位最长,根据 n 对 3 的余数可以分成三类:n % 3 == 0 时,需要按 21 的方式进行构造;n % 3 == 1 时,需要按 121 的方式构造;n % 3 == 2 时,需要按 212 的方式构造。

AC代码:

#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define mid (l + r >> 1)using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;int main(){//freopen("input.txt", "r", stdin);ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);int t;cin >> t;while(t--){int n;cin >> n;if(n % 3 == 0){while(n){cout << 21;n -= 3;}}else if(n % 3 == 1){while(n > 1){cout << 12;n -= 3;}cout << 1;}else{while(n > 2){cout << 21;n -= 3;}cout << 2;}cout << endl;}return 0;
}

B. Madoka and the Elegant Gift

题目链接:Problem - B - Codeforces

题目大意:在给定的图中找只包含 1 的最大矩形,如果至少有两个最大矩形发生交叉,这个图就是不优美的,输出NO,反之就是优美的,输出YES。下图就是一个不优美的图。

解题思路:这里提供两种思路(第一种是我的思路,第二种是同学的思路),第一种是寻找 0 的位置,然后判断它的(左上、左、上)(右上、右、上)(左下、左、下)(右下、右、下)这四种情况是否存在一种都为 1,即构成 ”|_“ 的形状,如果有,那么这个图一定不优美。第二种是不管每个位置是 0 还是 1,遍历每个 2 * 2 的正方形,只要存在一个正方形中恰好 3 个点是 1,那么这个图一定不优美。

AC代码:

第一种:

#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define mid (l + r >> 1)using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
const int N = 105;
char a[N][N];
int n, m;bool check(int i, int j){if(a[i][j] == '0'){if(i > 1 && j > 1 && a[i - 1][j - 1] == '1' && a[i - 1][j] == '1' && a[i][j - 1] == '1') return true;if(i > 1 && j < m && a[i - 1][j] == '1' && a[i - 1][j + 1] == '1' && a[i][j + 1] == '1') return true;if(i < n && j > 1 && a[i + 1][j - 1] == '1' && a[i][j - 1] == '1' && a[i + 1][j] == '1') return true;if(i < n && j < m && a[i + 1][j] == '1' && a[i + 1][j + 1] == '1' && a[i][j + 1] == '1') return true;}return false;
}int main(){//freopen("input.txt", "r", stdin);ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);int t;cin >> t;while(t--){cin >> n >> m;for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){cin >> a[i][j];}}int flag = 0;for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){if(check(i, j)){flag = 1;break;}}}if(flag) cout << "NO" << endl;else cout << "YES" << endl;}return 0;
}

第二种:

#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define mid (l + r >> 1)using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
const int N = 105;
char a[N][N];
int n, m;bool check(int i, int j){int cnt = 0;if(a[i][j] == '1') cnt++;if(a[i + 1][j] == '1') cnt++;if(a[i][j + 1] == '1') cnt++;if(a[i + 1][j + 1] == '1') cnt++;if(cnt == 3) return true;return false;
}int main(){//freopen("input.txt", "r", stdin);ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);int t;cin >> t;while(t--){cin >> n >> m;for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){cin >> a[i][j];}}int flag = 0;for(int i = 1; i < n; i++){for(int j = 1; j < m; j++){if(check(i, j)){flag = 1;break;}}}if(flag) cout << "NO" << endl;else cout << "YES" << endl;}return 0;
}

C. Madoka and Childish Pranks

题目链接:Problem - C - Codeforces

题目大意:给定一个棋盘(1代表黑,0代表白),问是否能按照题目所给的上色方式(如下图,可选任意矩形大小进行上色,但必须与图相同,即第一格为白色,相邻的均为黑色)得到该棋盘,如果能,则输出上色操作数,然后每行输出四个数代表上色区域的左上角坐标(x1, y1)和右下角坐标(x2, y2);如果不能则输出-1。

解题思路:构造题,要想到除了(1, 1)为黑色的棋盘,任意一个棋盘都可以由 1 * 2 或 2 * 1 的矩形上色方式进行上色得到。想到这个就好办了,只需要从下往上,从右往左进行上色,遇到 1 就进行一个 1 * 2 的上色,当遇到最左边出现 1 时,作一个 2 * 1 的上色,每次将答案存入 vector 就行了。

AC代码:

#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define mid (l + r >> 1)using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
const int N = 105;
char a[N][N];
int n, m;vector<PII> ans;int main(){//freopen("input.txt", "r", stdin);ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);int t;cin >> t;while(t--){cin >> n >> m;ans.clear();for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){cin >> a[i][j];}}if(a[1][1] == '1'){cout << -1 << endl;continue;}for(int i = n; i >= 1; i--){for(int j = m; j >= 1; j--){if(j == 1 && a[i][j] == '1'){ans.push_back({i - 1, j});ans.push_back({i, j});continue;}if(a[i][j] == '1'){ans.push_back({i, j - 1});ans.push_back({i, j});}}}int len = ans.size();cout << len / 2 << endl;for(int i = 0; i < len; i += 2){cout << ans[i].first << ' ' << ans[i].second << ' ' << ans[i + 1].first << ' ' << ans[i + 1].second << endl;}}return 0;
}

【记录CF】Codeforces Round #777 (Div. 2) A~C 题解相关推荐

  1. [CF]Codeforces Round #529 (Div. 3)

    [CF]Codeforces Round #529 (Div. 3) C. Powers Of Two Description A positive integer xx is called a po ...

  2. Codeforces Round #777 (Div. 2) 简训

    Codeforces Round #777 (Div. 2) 简训 导语 涉及的知识点 题目 A Madoka and Math Dad B Madoka and the Elegant Gift C ...

  3. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  4. Codeforces Round #774 (Div. 2)E题题解

    Codeforces Round #774 (Div. 2) E. Power Board 题目陈述 有一个n×m(1≤n,m≤106)n\times m(1\le n,m\le10^6)n×m(1≤ ...

  5. 【CF补题】【ABC】Codeforces Round #777 (Div. 2) C++代码

     A. Madoka and Math Dad [题意]求连续不带零且不相等位数的最大十进制数,使其位数之和为 n.有t个测试n [思考]根据样例我们就可以推测答案是121212...或212121. ...

  6. Codeforces Round #777 (Div. 2) 题解

    Codeforces #777 题解 这次带上了大佬前来验题xs 公开大佬珍贵的代码资源供参考 TOC A.Madoka and Math Dad B.Madoka and the Elegant G ...

  7. [CF]Codeforces Round #528 Div.2

    Div.2还是稳定四题啊,E题还是没得办法,就争取四题再快点吧. A(签到) 题意:写下s的第一个字符,在最右边写下s的第二个字符,在最左边写下s的第三个字符,以此类推生成字符串t,给出t,求s 找规 ...

  8. Codeforces Round #777 (Div. 2)【未完结】

    老年选手,做个签到就溜了. 现在才开始补题,cf分一直上不去. 目录 A. Madoka and Math Dad[构造] B. Madoka and the Elegant Gift[连通块] C. ...

  9. Codeforces Round #777 (Div. 2) ABCD题解

    A-Madoka and Math Dad 题目大意: 一个十进制数字(不含0),各个位上的和为n(n<=1000),且相邻位没有相同的数字,问这个数字最大可以是多少. 思路: 显然要使这个数字 ...

最新文章

  1. 深度学习与传统图像识别
  2. PHP5 $this self parent static的区别
  3. cocos2d-js 3.0 RC0 监听返回键、菜单键、进入后台(home键)、恢复显示等事件
  4. linux环境下python的部署
  5. python 机器学习中,clf变量代表的是什么意思?(clf = classifier的缩写 分类器)
  6. Java11-day02【多态(成员访问、多态转型、内存图解)、抽象类(成员特点)、接口(成员特点)、类和接口的关系、抽象类和接口的区别、综合案例】
  7. BM15 删除有序链表中重复的元素-I
  8. python——面向对象篇之异常和反射
  9. mybatis新增返回主键值
  10. 学编程面试通不过_我从编程面试中学到了什么
  11. php字符串中删除字符串函数,PHP 实现删除任意区间内字符串函数方法
  12. Shell 的基础知识
  13. can是什么时候处于显性_CAN总线边沿时间标准是什么?
  14. 海量文件或数据 导致高并发,高流量处理方案
  15. 错误 C2280 Union : 尝试引用已删除的函数 以及 警告 C4624 “Grade”: 已将析构函数隐式定义为“已删除”的一种解决方法...
  16. 计算机网络知识点全面总结(有这一篇就够了!!!)
  17. if while的用法
  18. 微信公众号订阅号开发的学习(一):基础知识
  19. 配音秀 v8.10.255
  20. FastDb client-server模式

热门文章

  1. 无障碍建筑设计相关术语
  2. 计算机应用基础课程的评价方法,对计算机应用基础课程评价方法探讨.doc
  3. OmniPlan,一款让你爱不释手的项目管理工具
  4. php仿u8系统模板_u8cloud操作步骤!
  5. 在使用计算机时可以用什么键关机,电脑死机按什么键关机重启
  6. linux下载百度命令行,Linux 命令行使用百度网盘上传下载文件
  7. Android小应用——监控屏幕使用时间
  8. 游戏外挂防封心得防检测防封技术
  9. atm系统的用例模型_ATM自动取款机用例图.doc-_装配图网
  10. 一点就分享系列(实践篇3-上篇)— 修改YOLOV5 之”魔刀小试“+ Trick心得分享+V5精髓部分源码解读