CodeForces 1983B Corner Twist
1.CodeForces 1992E Novice's Mistake2.CodeForces 1935A Entertainment in MAC3.CodeForces 1992C Gorilla and Permutation4.CodeForces 1992D Test of Love5.CodeForces 1992B Angry Monk6.CodeForces 1992A Only Pluses
7.CodeForces 1983B Corner Twist
8.CodeForces 1983A Array Divisibility9.CodeForces 1983C Have Your Cake and Eat It Too10.CodeForces 1883B Chemistry11.CodeForces 1883A Morning12.CodeForces 1883C Raspberries13.CodeForces 1883D In Love14.CodeForces 1883E Look Back15.CodeForces 1883F You Are So Beautiful16.CodeForces 1883G1 Dances (Easy version)17.CodeForces 908B New Year and Buggy Bot18.CodeForces 908C New Year and Curling19.CodeForces 1132B Discounts20.CodeForces 1619D New Year's Problem21.Codeforces Round 964 (Div. 4)题目链接:CodeForces 1983B【Corner Twist】
思路
可以发现操作一次,被操作位置的对应每一横行和每一纵行的加减数都是3,所以可以根据网格a和b的横纵状态确定是否通过操作使得网格a到达网格b。
代码
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 5e2 + 10; int a[N][N], b[N][N]; int main() { int t; cin >> t; while (t--) { memset(a, 0, sizeof a); memset(b, 0, sizeof b); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { string s; cin >> s; for (int j = 0; j < m; j++) { a[i][j + 1] = s[j] - '0'; a[i][j + 1] = a[i][j + 1] + a[i - 1][j + 1] + a[i][j] - a[i - 1][j]; } } for (int i = 1; i <= n; i++) { a[i][m + 1] = a[i][m] - a[i - 1][m]; } for (int i = 1; i <= m; i++) { a[n + 1][i] = a[n][i] - a[n][i - 1]; } for (int i = 1; i <= n; i++) { string s; cin >> s; for (int j = 0; j < m; j++) { b[i][j + 1] = s[j] - '0'; b[i][j + 1] = b[i][j + 1] + b[i - 1][j + 1] + b[i][j] - b[i - 1][j]; } } for (int i = 1; i <= n; i++) { b[i][m + 1] = b[i][m] - b[i - 1][m]; } for (int i = 1; i <= m; i++) { b[n + 1][i] = b[n][i] - b[n][i - 1]; } int flag = 0; for (int i = 1; i <= n; i++) { b[i][m + 1] = b[i][m] - b[i - 1][m]; if ((b[i][m + 1] - a[i][m + 1]) % 3 != 0) { cout << "NO" << endl; flag = 1; break; } } if (flag) { continue; } for (int i = 1; i <= m; i++) { b[n + 1][i] = b[n][i] - b[n][i - 1]; if ((b[n + 1][i] - a[n + 1][i]) % 3 != 0) { cout << "NO" << endl; flag = 1; break; } } if (flag) { continue; } cout << "YES" << endl; } return 0; }
合集:
Codeforces
分类:
ACM / 基础算法 / 思维
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】