CF1293C - NEKO's Maze Game 分块

一定是两个障碍物组成一对来破坏连通性,每个障碍物可能属于最多3对,然后维护障碍物对数就行。但是懒得讨论,暴力分块过了。

涉及到修改的块暴力重构这个块的连通性。只要左端两个位置和右端两个位置中任意两个可互达就具有连通性。

然后每次询问,就先看每个块的连通性,再看每个块之间是否成功的连接起来。

 1 #include <cstdio>
 2 #include <cmath>
 3 using namespace std;
 4 int n,q,m,M,acc[1100],mp[3][110000];
 5 int id(int x)
 6 {
 7     return (x + M - 1) / M;
 8 }
 9 bool check()
10 {
11     for (int i = 1;i <= m;i++)
12         if (acc[i] == false)
13             return false;
14     for (int i = 1;i <= m;i++)
15         if (!((mp[1][(i - 1) * M + 1] == 1 && mp[1][(i - 1) * M] == 1) || (mp[2][(i - 1) * M + 1] == 1 && mp[2][(i - 1) * M] == 1)))
16         {
17             return false;
18         }
19     return true;
20 }
21 bool dfs(int x,int tar,int sta1,int sta2)
22 {
23     if (x == tar)
24         return true;
25     int new1 = 0,new2 = 0;
26     if (sta1 && mp[1][x + 1] == 1)
27         new1 = 1;
28     if (sta2 && mp[2][x + 1] == 1)
29         new2 = 1;
30     if ((new1 == 1 || new2 == 1) && mp[1][x + 1] == 1 && mp[2][x + 1] == 1)
31         new1 = new2 = 1;
32     if (new1 || new2)
33         return dfs(x + 1,tar,new1,new2);
34     else
35         return false;
36 }
37 void change(int x,int y)
38 {
39     mp[x][y] ^= 1;
40     if (dfs((id(y) - 1) * M,id(y) * M,1,1))
41         acc[id(y)] = 1;
42     else
43         acc[id(y)] = 0;
44 }
45 int main()
46 {
47     scanf("%d%d",&n,&q);
48     M = sqrt(n);
49     m = id(n);
50     for (int i = 0;i <= m * M;i++)
51         mp[1][i] = mp[2][i] = 1;
52     for (int i = 1;i <= m;i++)
53         acc[i] = 1;
54     int tr,tc;
55     for (int i = 1;i <= q;i++)
56     {
57         scanf("%d%d",&tr,&tc);
58         change(tr,tc);
59         if (check())
60             printf("Yes\n");
61         else
62             printf("No\n");
63     }
64     return 0;
65 }

CF1293C - NEKO's Maze Game 分块

原文地址:https://www.cnblogs.com/iat14/p/12272037.html

时间: 2024-08-01 05:51:56

CF1293C - NEKO's Maze Game 分块的相关文章

Codeforces Round #614 (Div. 2) C. NEKO&#39;s Maze Game

题目链接:http://codeforces.com/contest/1293/problem/C 题意:给定n,q,即给定一个2*n的格子,有q个查询. 每个查询给定一个ri和ci,ri为1或2,ci在1到n之间,即给定一个(ri,ci),该点自该查询起状态进行转变(可经过/不可经过). 如某个查询给定1,2,即点(1,2)无法经过,若之后查询再次给定1,2,则该点(1,2)可以经过. 问能否从(1,1)走到(2,n),保证给定的查询不会经过起点和终点. 思路: 由于n和q最大都是1e5,所以

题解 CF1292A 【NEKO&#39;s Maze Game】

有一个结论: 当 \((1,1)\) 不能抵达 \((2,n)\) 时,必定存在一个点对,这两个点的值均为真,且坐标中的 \(x\) 互异,\(y\) 的差 \(\leq 1\) 这个结论的正确性感觉非常显然,就不多说了. 下图可以形象地解释点对的位置关系. 那对于每个点的值,只要开一个数组 f[i][j] 记录一下即可. 有了上述结论,我们记一个变量 \(cnt\) 表示 " 有多少对满足上述结论的点对 " ,则 \(cnt=0\) 时,\((1,1)\) 可以抵达 \((2,n)\

CodeForces 1292A NEKO&#39;s Maze Game(思维)

1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <string> 5 #include <math.h> 6 #include <algorithm> 7 #include <vector> 8 #include <stack> 9 #include <queue> 10 #include <

NEKO&#39;s Maze Game-cf

题意:给你一个2×n的矩阵,起点在左上,终点在右下,可以移动到本格相邻的格子里,给你q个时间点,每个时间点会有一个格子的状态发生变化,格子状态分为可走和不可走,一开始所以格子都是可走的,要求输出每个时间点能不能从起点走到终点. 思路:对任意格子来说,设它的坐标为x,y,对于他的另一行的三个坐标3-x,y-1  ,3-x,y和3-x,y+1有一个是不可走的,整个道路就被塞死了,就无法从起点走到终点.也就是说整个矩阵任意一个点满足这种关系,整条路走不通,所以我们统计整个矩阵有多少组这种关系设为num

#614 C. NEKO&#39;s Maze Game

起初一直看不懂题的意思,最后看了大佬的视频讲解才明白了题的意思. 题意:每次询问重复的时候抵消上一次操作  如果是奇数次的操作则视为障碍阻挡前进 收获:0和1的转换技巧,简单搜索和巧定义全局变量,没必要一定要写出来函数 非函数写法: #include<bits/stdc++.h> using namespace std; const int N=1e5+5; int a[2][N]; int main() { int n,q;int obstacle=0; cin>>n>&g

CF 1912 A NEKO&#39;s Maze Game

题目传送门 题目描述 NEKO#ΦωΦ has just got a new maze game on her PC! The game's main puzzle is a maze, in the forms of a 2×n2×n rectangle grid. NEKO's task is to lead a Nekomimi girl from cell (1,1)(1,1) to the gate at (2,n)(2,n) and escape the maze. The girl

Codeforces Round #614 (Div. 2)

A. ConneR and the A.R.C. Markland-N 题目链接:https://codeforces.com/contest/1293/problem/A 题意: 有一个长为 n 的楼层,其中有 k 个楼层没有餐厅 ,你现在在 s 层,问你最少走多少个楼层可以到达餐厅吃饭 分析: 因为 k 只有 1000,所以直接往 s 层上下方找(当找到 0 或者 n + 1 时说明这个方向没有答案) #include<bits/stdc++.h> using namespace std;

Codeforces Round #614

NEKO's Maze Game 题意 题解 代码 Aroma's Search 题意 题解 代码 Xenon's Attack on the Gangs 题意 题解 代码 NEKO's Maze Game 题目链接 https://codeforces.com/contest/1292/problem/A 题意 给出一个 2xN 的地图,每一时刻都有一个位置翻转状态(可走和不可走变换),输出每时刻是否可以从起点走到终点. 题解 地图只有 2xN,两个跨行相邻的位置不可走从起点就走不到终点. [

hdu 5094 Maze bfs+状态压缩

Maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others) Total Submission(s): 642    Accepted Submission(s): 229 Problem Description This story happened on the background of Star Trek. Spock, the deputy captain of St