当前位置: 首页 > wzjs >正文

免费安全网站认证企业网站设计策划

免费安全网站认证,企业网站设计策划,长沙网站seo费用,手机制作ppt的软件免费本文涉及知识点 CBFS算法 P10864 [HBCPC2024] Genshin Impact Startup Forbidden II 题目描述 弹窗内容 LeavingZ:你被禁止玩《原神》。 蓝边铅球因LeavingZ的禁止而无法玩《原神》,所以她转向了围棋。 围棋游戏由两名玩家进行,一方使…

本文涉及知识点

C++BFS算法

P10864 [HBCPC2024] Genshin Impact Startup Forbidden II

题目描述

弹窗内容

LeavingZ:你被禁止玩《原神》。

蓝边铅球因LeavingZ的禁止而无法玩《原神》,所以她转向了围棋。

围棋游戏由两名玩家进行,一方使用黑子,另一方使用白子。两名玩家轮流下子,黑子先行。围棋棋盘由 19 × 19 19\times 19 19×19的交叉点组成,我们用 ( x , y ) (x,y) (x,y)表示第 x x x行第 y y y列的交叉点。棋子放置在交叉点上。左上角为 ( 1 , 1 ) (1,1) (1,1),右下角为 ( 19 , 19 ) (19,19) (19,19)

如果 ∣ x 1 − x 2 ∣ + ∣ y 1 − y 2 ∣ = 1 |x_1-x_2| + |y_1-y_2| = 1 x1x2+y1y2=1,那么交叉点 ( x 1 , y 1 ) (x_1,y_1) (x1,y1) ( x 2 , y 2 ) (x_2,y_2) (x2,y2)是相邻的。相邻的交叉点上放置相同颜色的棋子属于同一组棋子。一个棋子的“气”数等于该棋子所在交叉点的相邻交叉点上没有棋子的个数。一组棋子的“气”数等于该组棋子中所有棋子的“气”数之和。一组棋子如果“气”数为零,则被视为“死棋”并且必须从棋盘上移除。

注意,在黑子落子后,优先移除任何死掉的白子,然后重新计算黑子的“气”数。这是因为可能出现这样的情况:黑子落子后,黑白两方的棋子都没有“气”,但移除死掉的白子会增加黑子的“气”。白子落子的处理方式类似。在白子落子后,优先移除任何死掉的黑子,然后重新计算白子的“气”数。

现在有一局围棋,从空棋盘开始,总共进行了 m m m步。给定每步棋子的放置位置,请输出每步棋子落子后,分别有多少颗黑子和白子被移除。显然,黑子在奇数步落子,白子在偶数步落子。保证棋子放置在空的交叉点上。注意,棋子可以放置在 任意 \textbf{任意} 任意当前没有棋子的交叉点上,无论是否违反了现实中的围棋规则 ( 1 ) ^{(1)} (1)

注释:

  • (2):译者补充

输入格式

输入包含 m m m 行( 1 ≤ m ≤ 5 × 1 0 5 1 \le m \le 5\times 10^5 1m5×105),第 i i i 行包含两个整数 x i , y i x_i, y_i xi,yi 1 ≤ x i , y i ≤ 19 1 \le x_i, y_i \le 19 1xi,yi19),表示第 i i i 步在 ( x i , y i ) (x_i, y_i) (xi,yi) 位置放置棋子。

保证棋子放置在当前没有棋子的交叉点上。

输出格式

输出包含 m m m 行,每行包含两个整数。第 i i i 行的第一个整数表示第 i i i 步后被移除的黑子数量,第二个整数表示被移除的白子数量。

翻译者:Immunoglobules

输入输出样例 #1

输入 #1

8
2 1
1 1
1 2
2 2
1 1
1 3
2 3
3 1

输出 #1

0 0
0 0
0 1
0 0
0 0
0 0
0 0
3 0

BFS

性质一:某组棋没死,在(x,y)处下棋后变死棋。说明:a,下棋之前,至少相邻一个空位。b,下棋之后没空位了。故(x,y)就是相邻的棋子。
结论一:以下黑子为例。grid[x][y]=1后,分别枚举grid[x1][y1]为-1的相邻单格是否是死棋,如果是死棋移除。判断grid[x][y]所在连通区域是否是死棋,如果是移除。
时间复杂度:O ( 19 × 19 × M ) ≈ 2 × 1 0 8 (19\times 19 \times M) \approx 2\times 10^8 (19×19×M)2×108,本题时间限制4s。
注意:判断grid[x][y]所在连通区域是否是死棋,必须BFS完。背景色没有棋子,蓝色和绿色是白棋,黑色是黑棋。如果蓝色格子BFS到左边,就提前结束。那绿色就BFS不到蓝色格子(已访问)。
![![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/eaa205e54f974bce87eecbf8e9e508a3.png](https://i-blog.csdnimg.cn/direct/97f52fbbf81e411db4ca2517ae5f3802.png

代码

核心代码

#include <iostream>
#include <sstream>
#include <vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<string>
#include<algorithm>
#include<functional>
#include<queue>
#include <stack>
#include<iomanip>
#include<numeric>
#include <math.h>
#include <climits>
#include<assert.h>
#include<cstring>
#include<list>#include <bitset>
using namespace std;template<class T1, class T2>
std::istream& operator >> (std::istream& in, pair<T1, T2>& pr) {in >> pr.first >> pr.second;return in;
}template<class T1, class T2, class T3 >
std::istream& operator >> (std::istream& in, tuple<T1, T2, T3>& t) {in >> get<0>(t) >> get<1>(t) >> get<2>(t);return in;
}template<class T1, class T2, class T3, class T4 >
std::istream& operator >> (std::istream& in, tuple<T1, T2, T3, T4>& t) {in >> get<0>(t) >> get<1>(t) >> get<2>(t) >> get<3>(t);return in;
}template<class T = int>
vector<T> Read() {int n;cin >> n;vector<T> ret(n);for (int i = 0; i < n; i++) {cin >> ret[i];}return ret;
}
template<class T = int>
vector<T> ReadNotNum() {vector<T> ret;T tmp;while (cin >> tmp) {ret.emplace_back(tmp);if ('\n' == cin.get()) { break; }}return ret;
}template<class T = int>
vector<T> Read(int n) {vector<T> ret(n);for (int i = 0; i < n; i++) {cin >> ret[i];}return ret;
}template<int N = 1'000'000>
class COutBuff
{
public:COutBuff() {m_p = puffer;}template<class T>void write(T x) {int num[28], sp = 0;if (x < 0)*m_p++ = '-', x = -x;if (!x)*m_p++ = 48;while (x)num[++sp] = x % 10, x /= 10;while (sp)*m_p++ = num[sp--] + 48;AuotToFile();}void writestr(const char* sz) {strcpy(m_p, sz);m_p += strlen(sz);AuotToFile();}inline void write(char ch){*m_p++ = ch;AuotToFile();}inline void ToFile() {fwrite(puffer, 1, m_p - puffer, stdout);m_p = puffer;}~COutBuff() {ToFile();}
private:inline void AuotToFile() {if (m_p - puffer > N - 100) {ToFile();}}char  puffer[N], * m_p;
};template<int N = 1'000'000>
class CInBuff
{
public:inline CInBuff() {}inline CInBuff<N>& operator>>(char& ch) {FileToBuf();ch = *S++;return *this;}inline CInBuff<N>& operator>>(int& val) {FileToBuf();int x(0), f(0);while (!isdigit(*S))f |= (*S++ == '-');while (isdigit(*S))x = (x << 1) + (x << 3) + (*S++ ^ 48);val = f ? -x : x; S++;//忽略空格换行		return *this;}inline CInBuff& operator>>(long long& val) {FileToBuf();long long x(0); int f(0);while (!isdigit(*S))f |= (*S++ == '-');while (isdigit(*S))x = (x << 1) + (x << 3) + (*S++ ^ 48);val = f ? -x : x; S++;//忽略空格换行return *this;}template<class T1, class T2>inline CInBuff& operator>>(pair<T1, T2>& val) {*this >> val.first >> val.second;return *this;}template<class T1, class T2, class T3>inline CInBuff& operator>>(tuple<T1, T2, T3>& val) {*this >> get<0>(val) >> get<1>(val) >> get<2>(val);return *this;}template<class T1, class T2, class T3, class T4>inline CInBuff& operator>>(tuple<T1, T2, T3, T4>& val) {*this >> get<0>(val) >> get<1>(val) >> get<2>(val) >> get<3>(val);return *this;}template<class T = int>inline CInBuff& operator>>(vector<T>& val) {int n;*this >> n;val.resize(n);for (int i = 0; i < n; i++) {*this >> val[i];}return *this;}template<class T = int>vector<T> Read(int n) {vector<T> ret(n);for (int i = 0; i < n; i++) {*this >> ret[i];}return ret;}template<class T = int>vector<T> Read() {vector<T> ret;*this >> ret;return ret;}
private:inline void FileToBuf() {const int canRead = m_iWritePos - (S - buffer);if (canRead >= 100) { return; }if (m_bFinish) { return; }for (int i = 0; i < canRead; i++){buffer[i] = S[i];//memcpy出错			}m_iWritePos = canRead;buffer[m_iWritePos] = 0;S = buffer;int readCnt = fread(buffer + m_iWritePos, 1, N - m_iWritePos, stdin);if (readCnt <= 0) { m_bFinish = true; return; }m_iWritePos += readCnt;buffer[m_iWritePos] = 0;S = buffer;}int m_iWritePos = 0; bool m_bFinish = false;char buffer[N + 10], * S = buffer;
};class CGrid {
public:CGrid(int rCount, int cCount) :m_r(rCount), m_c(cCount) {}template<class Fun1, class Fun2>vector<vector<pair<int, int>>> NeiBo(Fun1 funVilidCur, Fun2 funVilidNext, int iConnect = 4){vector<vector<pair<int, int>>> vNeiBo(m_r * m_c);for (int r = 0; r < m_r; r++){for (int c = 0; c < m_c; c++){if (!funVilidCur(r, c))continue;auto& v = vNeiBo[Mask(r, c)];if ((r > 0) && funVilidNext(r - 1, c)) {v.emplace_back(r - 1, c);}if ((c > 0) && funVilidNext(r, c - 1)) {v.emplace_back(r, c - 1);}if ((r + 1 < m_r) && funVilidNext(r + 1, c)) {v.emplace_back(r + 1, c);}if ((c + 1 < m_c) && funVilidNext(r, c + 1)) {v.emplace_back(r, c + 1);}}}return vNeiBo;}vector<vector<int>> Dis(vector<pair<int, int>> start, std::function<bool(int, int)> funVilidCur, std::function<bool(int, int)> funVilidNext, const int& iConnect = 4) {static short dir[8][2] = { {0, 1}, {1, 0}, {-1, 0},{ 0, -1},{1,1},{1,-1},{-1,1},{-1,-1} };vector<vector<int>> vDis(m_r, vector<int>(m_c, -1));for (const auto& [r, c] : start) {vDis[r][c] = 0;}for (int i = 0; i < start.size(); i++) {const auto [r, c] = start[i];if (!funVilidCur(r, c)) { continue; }for (int k = 0; k < iConnect; k++) {const int r1 = r + dir[k][0];const int c1 = c + dir[k][1];if ((r1 < 0) || (r1 >= m_r) || (c1 < 0) || (c1 >= m_c)) { continue; }if (funVilidNext(r1, c1) && (-1 == vDis[r1][c1])) {start.emplace_back(r1, c1);vDis[r1][c1] = vDis[r][c] + 1;}}}return vDis;}void EnumGrid(std::function<void(int, int)> call){for (int r = 0; r < m_r; r++){for (int c = 0; c < m_c; c++){call(r, c);}}}vector<pair<int, int>> GetPos(std::function<bool(int, int)> fun) {vector<pair<int, int>> ret;for (int r = 0; r < m_r; r++){for (int c = 0; c < m_c; c++){if (fun(r, c)) {ret.emplace_back(r, c);}}}return ret;}inline int Mask(int r, int c) { return  m_c * r + c; }const int m_r, m_c;const inline static int s_Moves[][2] = { {1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1} };
};class Solution {public:vector<pair<int,int>> Ans(vector<pair<int,int>>& ope) {CGrid ng(19, 19);auto Vilid = [&](int r, int c) {return true; };auto neiBo = ng.NeiBo(Vilid, Vilid);int grid[19][19] ;//黑子0,白子1,无子-1memset(grid, -1, sizeof(grid));int vis[19][19] = { 0 };auto BFS = [&](int r, int c, const int val) {vector<pair<int, int>> v;auto Add = [&](int r, int c, const int val){if (val != grid[r][c]) { return; }if (vis[r][c]) { return; }vis[r][c] = 1;v.emplace_back(r, c);};Add(r, c, val);bool bDead = true;for (int i = 0; i < v.size(); i++) {for (auto [r1, c1] : neiBo[ng.Mask(v[i].first, v[i].second)]) {if (-1 == grid[r1][c1]) { bDead = false;; }//至少一气Add(r1, c1, val);}}if (!bDead) { return 0; }for (const auto& [r, c] : v) {grid[r][c] = -1;}return (int)v.size();};	vector<pair<int, int>> ans;for (int i = 0; i < ope.size();i++) {auto [r, c] = ope[i];r--, c--;const int cur = i&1;const int other = cur^1;grid[r][c] = cur;int res[2] = { 0 };memset(vis, 0, sizeof(vis));for (const auto& [r1, c1] : neiBo[ng.Mask(r, c)]) {res[other] += BFS(r1, c1, other);}memset(vis, 0, sizeof(vis));res[cur] += BFS(r, c, cur);ans.emplace_back(res[0], res[1]);}return ans;}};int main() {
#ifdef _DEBUGfreopen("a.in", "r", stdin);
#endif // DEBUGios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);auto ope = Read<pair<int, int>>();
#ifdef _DEBUGOut(ope, "ope");
#endif // DEBUGauto res = Solution().Ans(ope);for (const auto& [i1, i2] : res) {cout << i1 << " " << i2 <<  "\n";}return 0;
}

单元测试

vector < pair<int, int>> ope;TEST_METHOD(TestMethod11){ope = { {2,1},{1,1},{1,2},{2,2},{1,1},{1,3},{2,3},{3,1} };auto res = Solution().Ans(ope);AssertV({ {0,0},{0,0},{0,1}, {0,0},{0,0}, {0,0},{0,0},{3,0} }, res);}

扩展阅读

我想对大家说的话
工作中遇到的问题,可以按类别查阅鄙人的算法文章,请点击《算法与数据汇总》。
学习算法:按章节学习《喜缺全书算法册》,大量的题目和测试用例,打包下载。重视操作
有效学习:明确的目标 及时的反馈 拉伸区(难度合适) 专注
闻缺陷则喜(喜缺)是一个美好的愿望,早发现问题,早修改问题,给老板节约钱。
子墨子言之:事无终始,无务多业。也就是我们常说的专业的人做专业的事。
如果程序是一条龙,那算法就是他的是睛
失败+反思=成功 成功+反思=成功

视频课程

先学简单的课程,请移步CSDN学院,听白银讲师(也就是鄙人)的讲解。
https://edu.csdn.net/course/detail/38771
如何你想快速形成战斗了,为老板分忧,请学习C#入职培训、C++入职培训等课程
https://edu.csdn.net/lecturer/6176

测试环境

操作系统:win7 开发环境: VS2019 C++17
或者 操作系统:win10 开发环境: VS2022 C++17
如无特殊说明,本算法用**C++**实现。


文章转载自:

http://n5dLEEoi.kgqpx.cn
http://Febrg3ZA.kgqpx.cn
http://ErZeHm2o.kgqpx.cn
http://K5IwENlu.kgqpx.cn
http://juLT7duc.kgqpx.cn
http://BpWQ6FN0.kgqpx.cn
http://cXujaxOr.kgqpx.cn
http://wT5iuG4d.kgqpx.cn
http://VYORVHrO.kgqpx.cn
http://ih12B2VW.kgqpx.cn
http://Yf6UpzFp.kgqpx.cn
http://NBu7PYod.kgqpx.cn
http://dB2Z8wft.kgqpx.cn
http://rZ2hLOz9.kgqpx.cn
http://Clm9vKoa.kgqpx.cn
http://h9XqtGTO.kgqpx.cn
http://mQRJmVCg.kgqpx.cn
http://vdPAn2Q5.kgqpx.cn
http://SFa0CiKM.kgqpx.cn
http://ACsBcrwt.kgqpx.cn
http://gN2nWBdN.kgqpx.cn
http://2X2ib3Uk.kgqpx.cn
http://5Vu1Q2D8.kgqpx.cn
http://grWJRWIn.kgqpx.cn
http://YQ1kO839.kgqpx.cn
http://30J9iffi.kgqpx.cn
http://AVAXILvi.kgqpx.cn
http://VCwUofy3.kgqpx.cn
http://FN5z5jKr.kgqpx.cn
http://nBmeleHe.kgqpx.cn
http://www.dtcms.com/wzjs/676784.html

相关文章:

  • 深圳网站开发哪个公司好海外社交媒体平台
  • 织梦网站更换域名新乡做新网站
  • 江苏省医院网站建设管理规范怎么恶意点击对手竞价
  • 闸北区网站设计与制作安顺建设工程造价管理网站
  • 朋友圈网站文章怎么做福建省住房城乡和城乡建设厅网站
  • 做非法网站人人设计网网址
  • 个人开店做外贸网站建设公司官网的请示
  • 代做原创毕业设计网站做网站需要公司备案
  • 济南外贸网站制作html制作网页的代码
  • 织梦禁止网站右击餐饮网站建设服务器
  • 锦州做网站公司合肥关键词网站排名
  • 企业网站设计过程中做网站页面用什么
  • 妇幼网站建设pptvue门户网站模板
  • 网站建设制作介绍河南seo优化方法有哪些
  • 大学生创业服务网站建设方案网站栏目排序
  • 包包网站建设策划书个人网站备案备注信息
  • 购物网站的建设思维导图做个网站上百度怎么做
  • wordpress仿站软件中裕隆建设有限公司网站
  • 网站导航栏代码常平哪里有招计算机网站开发的
  • 网站快照wordpress采集淘宝
  • 深圳市网站制作最好的公司163邮箱登录企业邮箱
  • 班级网站建设规划书国内外ai设计素材网站
  • 西安网站优化公司美食网站建设的意义
  • wordpress主题 淘宝客seo精华网站
  • 潍坊做网站联系方式网站建设课程教学计划
  • 苏州吴中区建设局网站哈尔滨做网站建设
  • 网站建设ssc源码平台济南活动搭建公司
  • 网站开发什么技术海东地网站建设
  • 将二级域名 网站目录做网站底色怎么选
  • 惠州市建网站公司开源项目网站