#614 C. NEKO'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>>q;
    while(q--)
    {
        int x,y;
        cin>>x>>y;x--,y--;
        if(a[x][y]==0)
        {
            a[x][y]=1;
            for(int i=-1;i<=1;++i){
                if(a[1-x][y+i]==1)
                    obstacle++;
            }
        }
        else
        {
            a[x][y]=0;
            for(int i=-1;i<=1;++i){
                if(a[1-x][y+i]==1){
                    obstacle--;
                }
            }
        }
        if(obstacle>0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

函数内写法:

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[2][N];
int obstacle=0,x,y,n,q;

void solve()
{
    int delta=(a[x][y]==0)?1:-1;
    a[x][y]=1-a[x][y];
    for(int i=-1;i<=1;++i){
        if(y+i>=n||y+i<0) continue;
        if(a[1-x][y+i]==1) obstacle+=delta;
    }

}
int main()
{
    cin>>n>>q;
    while(q--)
    {
        cin>>x>>y;x--,y--;
        solve();
        if(obstacle>0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

#614 C. NEKO's Maze Game

原文地址:https://www.cnblogs.com/waryan/p/12247170.html

时间: 2024-08-30 12:09:09

#614 C. 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

CF1293C - NEKO&#39;s Maze Game 分块

一定是两个障碍物组成一对来破坏连通性,每个障碍物可能属于最多3对,然后维护障碍物对数就行.但是懒得讨论,暴力分块过了. 涉及到修改的块暴力重构这个块的连通性.只要左端两个位置和右端两个位置中任意两个可互达就具有连通性. 然后每次询问,就先看每个块的连通性,再看每个块之间是否成功的连接起来. 1 #include <cstdio> 2 #include <cmath> 3 using namespace std; 4 int n,q,m,M,acc[1100],mp[3][11000

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