Codeforces Round #590 (Div. 3) C. Pipes
链接:
https://codeforces.com/contest/1234/problem/C
题意:
You are given a system of pipes. It consists of two rows, each row consists of n pipes. The top left pipe has the coordinates (1,1) and the bottom right — (2,n).
There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types:
Types of pipes
You can turn each of the given pipes 90 degrees clockwise or counterclockwise arbitrary (possibly, zero) number of times (so the types 1 and 2 can become each other and types 3,4,5,6 can become each other).
You want to turn some pipes in a way that the water flow can start at (1,0) (to the left of the top left pipe), move to the pipe at (1,1), flow somehow by connected pipes to the pipe at (2,n) and flow right to (2,n+1).
Pipes are connected if they are adjacent in the system and their ends are connected. Here are examples of connected pipes:
Examples of connected pipes
Let's describe the problem using some example:
The first example input
And its solution is below:
The first example answer
As you can see, the water flow is the poorly drawn blue line. To obtain the answer, we need to turn the pipe at (1,2) 90 degrees clockwise, the pipe at (2,3) 90 degrees, the pipe at (1,6) 90 degrees, the pipe at (1,7) 180 degrees and the pipe at (2,7) 180 degrees. Then the flow of water can reach (2,n+1) from (1,0).
You have to answer q independent queries.
思路:
记录当前位置和上一位置, 枚举情况即可.
代码:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10;
char Map[2][MAXN];
int n;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
scanf("%d\n", &n);
scanf("%s%s", Map[0], Map[1]);
int nowx = 0, nowy = 0, lasx = -1, lasy = -1;
bool flag = true;
while (nowy < n)
{
if (lasx == -1)
{
lasx = nowx, lasy = nowy;
if (Map[nowx][nowy]-'0' <= 2)
nowy++;
else
nowx ^= 1;
continue;
}
if (nowx == lasx)
{
if (Map[lasx][lasy]-'0' <= 2)
{
lasx = nowx, lasy = nowy;
if (Map[nowx][nowy]-'0' <= 2)
nowy++;
else
nowx ^= 1;
}
else
{
lasx = nowx, lasy = nowy;
if (Map[nowx][nowy]-'0' <= 2)
nowy++;
else
nowx ^= 1;
}
}
else
{
if (Map[lasx][lasy]-'0' <= 2)
{
flag = false;
break;
}
else
{
if (Map[nowx][nowy]-'0' <= 2)
{
flag = false;
break;
}
else
{
lasx = nowx, lasy = nowy;
nowy++;
}
}
}
}
// cout << line << endl;
if (!flag || nowx != 1)
puts("NO");
else
puts("YES");
}
return 0;
}
Codeforces Round #590 (Div. 3) C. Pipes的更多相关文章
- Codeforces Round #590 (Div. 3) Editorial
Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...
- Codeforces Round #590 (Div. 3)
A. Equalize Prices Again 题目链接:https://codeforces.com/contest/1234/problem/A 题意:给你 n 个数 , 你需要改变这些数使得这 ...
- Codeforces Round #590 (Div. 3)(e、f待补
https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...
- Codeforces Round #590 (Div. 3) E. Special Permutations
链接: https://codeforces.com/contest/1234/problem/E 题意: Let's define pi(n) as the following permutatio ...
- Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)
链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowerca ...
- Codeforces Round #590 (Div. 3) B2. Social Network (hard version)
链接: https://codeforces.com/contest/1234/problem/B2 题意: The only difference between easy and hard ver ...
- Codeforces Round #590 (Div. 3) A. Equalize Prices Again
链接: https://codeforces.com/contest/1234/problem/A 题意: You are both a shop keeper and a shop assistan ...
- Codeforces Round #590 (Div. 3) F
传送门 题意: 给出一个只含前\(20\)个字符的字符串,现在可以选择一段区间进行翻转,问区间中字符各不相同时,最长长度为多少. 思路: 首先,容易将题意转换为选择两个字符各不相同的区间,然后长度相加 ...
- Codeforces Round #590 (Div. 3) 万恶的自己WAC
C题:一道简单的C题卡了半天,我太菜了 题意:给你一个n*2的矩阵,每个位置有一个数字,对应一种管道,要求通道可不可以从左上通到右下 由提议可以看出,1,2对应的是直管道,3,4,5,6对应弯管道,只 ...
随机推荐
- 真理胜于一切 JAVA模拟表单提交
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...
- Vufuria入门 1 图片识别和选择
Vufutia中的图片识别功能,底层主要是识别特征点来实现的.特征点,即那些棱角分明的点.尖锐的而不是圆滑的.对比度大的而不是小的. *** 步骤: 进入vofuria官网,登录,点击develop. ...
- Python 流程控制与循环体
Python 的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承.Py ...
- HeidiSQL 导入Excel数据
一 前言 原文出处:http://blog.csdn.net/qq_27727681/article/details/53944744 二 效果演示: 2000多条数据,顺利导入成功. 三 实现方法 ...
- bzoj 2734 集合悬殊 (状压dp)
大意: 给定$n$, 求集合{1,2,...n}的子集数, 满足若$x$在子集内, 则$2x,3x$不在子集内. 记$f(x)$为$x$除去所有因子2,3后的数, 那么对于所有$f$值相同的数可以划分 ...
- 基于C#实现与新大陆扫码枪通信
随着工业互联的发展,扫码枪在很多场合都有所应用,超市.商场以及一些智能工厂.今天主要讲如何通过C#实现与新大陆扫码枪(OY10)进行通信,对于扫码枪的配置,这里就不多说了,结合说明书就可以实现.这里值 ...
- 网页接入dingding扫码登录
前言 有时候我们做了一些网页,希望只有某些人才能看的话,可以搞一个钉钉扫码登录,接入也比较简单,下面记录下接入的过程. 流程 我们先看看官方的文档:钉钉接入文档梳理一下官方的流程:1.先跳去一个扫码网 ...
- Kubernetes对象中的PersistentVolume、PersistentVolumeClaim和StorageClass的概念关系
Kubernetes容器要持久化数据,离不开volume,k8s的volume和Docker原生概念中的volume有一些差别,不过本次不讲这个,本次要明确的是k8s持久化数据用到的几个对象Persi ...
- 四:MVC之LINQ方法语法
linq 查询 有两种语法 ,前面我们说了一种,接下来说方法语法(我读着一直很绕口) 查询语法,方法语法 ------------------------以下文字都是复制-------------- ...
- JS中数组初始化以及赋值
.指定长度,然后初始化 ); ;index < ;index++){ vArray[index] = index; } 2.不指定长度,然后初始化 var vArray = new Array( ...