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对应弯管道,只 ...
随机推荐
- [转帖]龙芯:Docker 配置与实践清单
Docker 配置与实践清单 http://www.sohu.com/a/254904706_198222 文章对来官方文档及 Docker Links[1] 中链接内容进行归档整理,包含了日常工作中 ...
- fiddler模拟发送请求和响应
iddler模拟发送请求和响应 一.fiddler模拟发送请求 1.fiddler模拟发送get请求 1)例如:访问博客园https://www.cnblogs.com/,并且登录输入密码账号登录,再 ...
- NOIP2012 借教室 题解 洛谷P1083
一看就是暴力 好吧,其实是线段树或差分+二分,这里用的是差分+二分的做法. 二分部分的代码,套个二分板子就行 ,right=m; while(left<right)//二分 { ; ; else ...
- JS中json数组多字段排序方法(解决兼容性问题)(转)
前端对一个json数组进行排序,用户需要动态的根据自己的选择来对json数据进行排序. 由于后台表设计问题所以不能用sql进行排序,这里用到了js的sort方法. 如果对单字段排序,那么很简单,一个s ...
- Spring 自定义Bean 实例获取
一.通过指定配置文件获取, 对于Web程序而言,我们启动spring容器是通过在web.xml文件中配置,这样相当于加载了两次spring容器 ApplicationContext ac = new ...
- Angular6如何引入jQuery-knob
Angular6如何引入jQuery-knob 1.概述 Angular6引入jQuery变得异常简单,请参考https://blog.csdn.net/qq_35321405/article/det ...
- ItemsControl使用1
<ItemsControl ItemsSource="{Binding DataItemsSource}"> //绑定一个List <ItemsControl.I ...
- 【原创】编程基础之Jekins
Jenkins 2.164.2 官方:https://jenkins.io 一 简介 Build great things at any scale The leading open source a ...
- 手写map, filter函数
function map(arr, fn) { let newArr = []; for (let i = 0; i < arr.length; i++) { newArr[i] = fn(ar ...
- 许愿墙JQ
<!doctype html> <html> <head> <meta charset="utf-8"> <t ...