在4x4的棋盘上摆满了黑白棋子,黑白两色的位置和数目随机其中左上角坐标为(1,1),右下角坐标为(4,4),现在依次有一些翻转操作,要对一些给定支点坐标为中心的上下左右四个棋子的颜色进行翻转,请计算出翻转后的棋盘颜色。
2024-08-29 05:17:24
// ConsoleApplication10.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
using namespace std;
class Flip {
public:
vector<vector<int> > flipChess(vector<vector<int> > A, vector<vector<int> > f) {
for (int i = 0;i < f.size();i++)
{
int row = f[i][0];
int col = f[i][1];
if (row >= 0 && row < 4 && col - 1 >= 0 && col - 1 < 4)
{
if (A[row][col - 1] == 0) A[row][col - 1] = 1;
else A[row][col - 1] = 0;
}
if (row-2 >= 0 && row-2 < 4 && col - 1 >= 0 && col - 1 < 4)
{
if (A[row-2][col - 1] == 0) A[row-2][col - 1] = 1;
else A[row-2][col - 1] = 0;
}
if (row-1 >= 0 && row-1 < 4 && col >= 0 && col < 4)
{
if (A[row-1][col ] == 0) A[row-1][col ] = 1;
else A[row-1][col ] = 0;
}
if (row-1 >= 0 && row-1 < 4 && col - 2 >= 0 && col - 2 < 4)
{
if (A[row-1][col - 2] == 0) A[row-1][col - 2] = 1;
else A[row-1][col - 2] = 0;
}
}
return A;
}
};
int main()
{
Flip fl;
vector<int> A1 = { 0,0,1,1 };
vector<int> A2 = { 1,0,1,0 };
vector<int> A3 = { 0,1,1,0 };
vector<int> A4 = { 0,0,1,0 };
vector<vector<int> > A;
A.push_back(A1);
A.push_back(A2);
A.push_back(A3);
A.push_back(A4);
vector<int> f1 = { 2,2 };
vector<int> f2 = { 3,3 };
vector<int> f3 = { 4,4 };
vector<vector<int> > f;
f.push_back(f1);
f.push_back(f2);
f.push_back(f3);
vector<vector<int> > re= fl.flipChess(A, f);
return 0;
};
最新文章
- Git 版本库添加空目录方法
- 【leetcode】Merge Two Sorted Lists
- js给定时器调用传递参数
- openstack 基本配置
- ubuntukylin提取root权限及mongoDB部署
- Android Service 系统服务
- 这几天有django和python做了一个多用户博客系统(可选择模板)
- 手机下的ev.pageX无效
- 学习Robot Framework必须掌握的库—-BuiltIn库
- seq语句随笔
- ArcGIS制图技巧系列(2)地形渲染
- Oracle12c中数据泵新特性之功能增强(expdp, impdp)
- MySQL 笔记整理(19) --为什么我只查一行的语句,也执行这么慢?
- Uncaught DOMException: Failed to construct &#39;WebSocket&#39;: The URL
- Null component Catalina
- 与Recommender System相关的会议及期刊
- xshell下mysql数据库只导出表结构不导出数据
- maven依赖jar导出消失问题
- 大数据java基础day01
- mongodb基础环境搭建