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对应弯管道,只 ...
随机推荐
- poj1797(dijstra变形,求最小边的最大值)
题目链接:https://vjudge.net/problem/POJ-1797 题意:n个点,m条带权边,求点1到点n的所有路径中最小边的最大值. 思路: 和poj2253一样,只不过那题n< ...
- [CF1065F]Up and Down the Tree_tarjan_树形dp
Up and Down the Tree 题目链接:https://www.luogu.org/problem/CF1065F 数据范围:略. 题解: 我们把每个叶子向它上面$k$个点连边,然后tra ...
- [转帖]centos7设置CPU的运行频率为performance
centos7设置CPU的运行频率为performance http://www.512873.com/archives/612.html Publish: March 6, 2019 Categor ...
- 【转帖】sysbench压力测试工具简介
sysbench压力测试工具简介 https://www.cnblogs.com/pdlife/p/6698957.html 一.sysbench压力测试工具简介: sysbench是一个开源的.模块 ...
- IDEA插件之JProfiler
1.是什么?来用干嘛的? 一个商业授权的Java剖析工具. 用来剖析程序内存.CPU使用情况,找到性能瓶颈,快速定位问题所在. 2.IDEA安装JProfiler插件 (1)File -> Se ...
- 关于container_of函数分析
#include <stdio.h> #define offset_of(type,member) ((int)&(((type *)0)->member)) #define ...
- select key from table 一直出错
key和keys 为mysql 关键字,数据库设计字段的时候尽量避免
- 轻松入门CAS系列(1)-轻松看懂企业单点登录的解决方案
常见的企业应用情况 企业内部的信息化一般都是一个过程中的 ,起初企业为了部分管理的需要,会上线几个信息化系统:后来对这块慢慢重视,信息系统会越来越多.开始,只有一两个系统时,员工还好,靠脑袋还能记得住 ...
- WINAPI与CALLBACK
#define WINAPI __stdcall #define CALLBACK __stdcall 都是__stdcall,无本质区别. CALLBACK只是为了告诉我们这是一个回调函数.
- 9. Java分支语句之if...else
if...else条件语句 一个if语句包含一个布尔表达式和一条或者多条语句. 语法运用有三种 //第一种 if(布尔表达式){ //如果布尔表达式为true将执行的语句 } //第二种 if(布尔表 ...