CodeForces 1293 C NEKO's Maze Game
【题目大意】
有一个2 ∗ n的地图,小女孩从(1,1)想移动到(2,n)
有q次询问,每次询问更改一个格子状态(是否可以通过)
只能上下左右移动而不能斜着移动,问每次操作后,是否可以移动到(2,n)
【Input】
第一行n,q (数据范围1e5)
2 * n表示图的大小,q表示更改次数
以下q行,每行输入x,y表示更改点的坐标
【Output】
"Yes" or "No"
【Example】
input
5 5
2 3
1 4
2 4
2 3
1 4
output
Yes
No
No
No
Yes
【思路&分析】
老规矩,一切题目从暴力开始想
显然的,每次更新完用dfs暴搜
理想很丰满,现实很骨干
一看1 e 5, 一切都玩完
咳咳——换思路
仔细审题
我们发现—这个图是2 * n的
那么对于每个格子的两种状态,分类讨论
- 没有障碍物,可以通过(√)
- 有障碍物,我们可以选择绕行
如图所示,红色表示不可通过,蓝色表示可通过
若出现了红色部分,我们只需要判断其对面三个格子(图示第二行三个蓝格子)中有几个可通过
但凡有一个不可通过,则“No”
【代码实现】
需要二维数组保存状态
需要计数器数可以通行的格子
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; inline int read(){
int x = , w = ;
char ch = getchar();
for(; ch > '' || ch < ''; ch = getchar()) if(ch == '-') w = -;
for(; ch >= '' && ch <= ''; ch = getchar()) x = x * + ch - '';
return x * w;
} const int maxn = ; int n,q;
bool a[][maxn];
int ans; inline void check(int x, int y){
int tmp = ;
if(x == ) tmp = ;
else tmp = ;
if(a[x][y] == ){
if(a[tmp][y - ]) ans++;
if(a[tmp][y]) ans++;
if(a[tmp][y + ]) ans++;
}
else if(a[x][y] == ){
if(a[tmp][y - ]) ans--;
if(a[tmp][y]) ans--;
if(a[tmp][y + ]) ans--;
}
a[x][y] = !a[x][y];
} int main(){
n = read(), q = read();
while(q--){
int x = read(), y = read();
check(x, y);
if(!ans) cout << "Yes\n";
else cout << "No\n";
}
return ;
}
Code
CodeForces 1293 C NEKO's Maze Game的更多相关文章
- Codeforces 1292A/1293C - NEKO's Maze Game
题目大意: 有一个2*n的图 NEKO#ΦωΦ要带领mimi们从(1,1)的点走到(2,n)的点 每次会操作一个点,从可以通过到不可以通过,不可以通过到可以通过 每操作一次要回答一次NEKO#ΦωΦ能 ...
- 【迷宫问题】CodeForces 1292A A NEKO's Maze Game
题目大意 vjudge链接 共两行,从(1,n)到(2,n). 每过一个时刻会有一个位置的状态变化,从能到达这个位置变成不能到达,或从不能到达变成能到达,问在每个时刻中是否能从起点到终点. 数据范围 ...
- Codeforces Round #614 (Div. 2) C - NEKO's Maze Game
题目链接:http://codeforces.com/contest/1293/problem/C 题目:给定一个 2*n的地图,初始地图没有岩浆,都可以走, 给定q个询问,每个询问给定一个点(x,y ...
- NEKO's Maze Game - Codeforces 题解
题目 NEKO#ΦωΦ has just got a new maze game on her PC! The game's main puzzle is a maze, in the forms o ...
- CodeForces 1292A NEKO's Maze Game(思维)
#include <stdio.h> #include <string.h> #include <iostream> #include <string> ...
- Codeforces Round #614 (Div. 1) A. NEKO's Maze Game (思维,模拟)
题意:有一个\(2\)X\(n\)的矩阵,你想从\((1,1)\)走到\((2,n)\),每次可以向上下左右四个方向走,但在某些时间段某个点会被堵住,如果已经被堵住,那么即恢复正常,每次对某个点操作, ...
- Codeforces Round #222 (Div. 1) Maze —— dfs(连通块)
题目链接:http://codeforces.com/problemset/problem/377/A 题解: 有tot个空格(输入时统计),把其中k个空格变为wall,问怎么变才能使得剩下的空格依然 ...
- NEKO'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 ...
- 题解 CF1292A 【NEKO's Maze Game】
有一个结论: 当 \((1,1)\) 不能抵达 \((2,n)\) 时,必定存在一个点对,这两个点的值均为真,且坐标中的 \(x\) 互异,\(y\) 的差 \(\leq 1\) 这个结论的正确性感觉 ...
随机推荐
- Pi-star MMDVM双工板介绍
Pi-star MMDVM双工板介绍(2020/2) pi-star里控制模式选择:双工模式(DUPLEX Mode)/单工模式(SIMPLE Mode) 双工板工作频率范围:144-148,219- ...
- 点击 button 自动刷新页面
问题:为什么点击 button 会刷新页面 ? 原因:你代码的写法可能如下图,把 <button> 按钮 写在 <form> </form> 标签里边啦. < ...
- linux下使用tcpdump抓包分析tcp的三次握手
首先贴上tcp 三次握手的原理图服务器开启ftp服务并执行tcpdump抓包服务器:192.168.3.14 ftp服务客户端:192.168.3.100 服务器执行以下命令,客户端访问服务器ftp: ...
- centos7 yum源更新
先进入到yum源文件cd /etc/yum.repo.d/ 1.创建一个repo_bak目录,用于保存系统中原来yum的repo文件. sudo mkdir repo_bak 2.备份yum源文件至 ...
- MIPI CSI-2
目录 1 MIPI简介 2 MIPI CSI-2简介 2.1 MIPI CSI-2 的层次结构 2.2 CSI-2协议层 2.3 打包/解包层 2.4 LLP(Low Level Protocol)层 ...
- zabbix 大流量断图
一. 环境介绍 系统版本:Centos7.4 zabbix-agent 版本:zabbix-agent 3.4.7 二. 问题现象 在使用zabbix的snmp方式的监控端口流量时,某一个图总是断 ...
- 掌握SpringBoot-2.3的容器探针:实战篇
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:原创文章分类汇总,及配套源码,涉及Java.Docker.K8S.DevOPS等 经过多篇知识 ...
- 全网最全95道MongoDB面试题1万字详细解析
1.mongodb是什么? MongoDB 是由 C++语言编写的,是一个基于分布式文件存储的开源数据库系统. 在高负载的情况下,添加更多的节点,可以保证服务器性能. MongoDB 旨在给 WEB ...
- ubuntu12.04 dnw2 fl2440 配置
1.安装libusb-dev sudo apt-get install libusb-dev 2.dnw2编译配置 源码如下,将其保存为dnw2.c 编译命令 gcc dnw2.c -o dnw2 - ...
- DML_Data Modification_INSERT
Data Modification (INSERT.DELETE.UPDATE.MERGE)之INSERT(基础知识,算是20年来第2次学习MSSQL吧,2005年折腾过一段时间的Oracle)INS ...